const VERSION = String.fromEnvironment('VERSION', 'v0.0.0'); // 切记!!必须是常量类型才能替换
const PLATFORM = String.fromEnvironment('PLATFORM', 'android');

main() {
    print("VERSION: " + VERSION);
    print(const String.fromEnvironment('PLATFORM', 'android')); // 以常量形式访问
}

dart compile exe -DVERSION=v1.0.1 -DPLATFORM=android main.dart
dart -DVERSION=v1.0.1 -DPLATFORM=android main.dart
flutter build web --dart-define=VERSION=v1.0.1 --dart-define=PLATFORM=android

标签: none

添加新评论