language icon indicating copy to clipboard operation
language copied to clipboard

Conditional imports or compilation

Open TheCarpetMerchant opened this issue 2 months ago • 5 comments

Have a way of not importing irrelevant packages in a flutter web config, or allow conditionnal imports without the need for stubs (ie conditional compilation flags).

TheCarpetMerchant avatar Oct 26 '25 16:10 TheCarpetMerchant

import 'package:xxx-only_web_import/src/blob_url_empt.dart' if (dart.library.js_interop) 'src/blob_url.dart';

qcks avatar Oct 28 '25 12:10 qcks

Yes but then I have to make stubs for every package not invoved in the web config. Would be better to be able to not compile the code in the config at all, like Delphi does with compiler defines.

TheCarpetMerchant avatar Nov 01 '25 15:11 TheCarpetMerchant

Const if blocks?

void procedure<T>(T event) {
  const if (dart.library.js_interop) {
    // JS code.
  } else {
    // IO code.
  }
}

ykmnkmi avatar Nov 03 '25 05:11 ykmnkmi

Compile time code would be clearer as it can show exactly where the branch occurs and - on compilation - if the import is not used after compile time logic is computed then the imported code can be optimized out

RohitSaily avatar Nov 04 '25 18:11 RohitSaily

Compile time code would be clearer as it can show exactly where the branch occurs and - on compilation - if the import is not used after compile time logic is computed then the imported code can be optimized out

Yep. When I look at my 10MB dart.js I see plenty of packages that are android-only mentionned. Since download size is a major concern for web apps optimizing this would be amazing.

TheCarpetMerchant avatar Nov 17 '25 19:11 TheCarpetMerchant