localizely / flutter-intl-intellij

This Android Studio & IntelliJ plugin generates boilerplate code for localization of Flutter apps with official Dart Intl library
MIT License
129 stars 4 forks source link

Generates uncompilable code in Flutter release 3 #84

Closed absar closed 2 years ago

absar commented 2 years ago

Generates uncompilable code in Flutter release 3 with latest flutter intl plugin, however it works fine if Flutter is downgraded to 2.10 l10n.dart Generated code with Flutter 3: image

l10n.dart Generated code with Flutter 2.10: image

aleksakrstic commented 2 years ago

Hi @absar Thanks for reporting this! I don't have these issues with Flutter 3, so could you give me more info about your setup. Like:

absar commented 2 years ago

Thanks for the quick response, strangely it shows intl_utils 1.9.0, doesn't the IDE plugin use the latest one?

On further investigation this is what is happening. If I try to deactivate the package using flutter 2.10, it shows intl_utils 2.6.1, whereas 3 shows intl_utils 1.9.0, not sure why flutter 3 is using 1.9 on the same PC

Using flutter 2.10: flutter pub global deactivate intl_utils Deactivated package intl_utils 2.6.1

Using flutter 3: flutter pub global deactivate intl_utils Deactivated package intl_utils 1.9.0

When I change an ARB file right after upgrading to flutter 3, these are the messages, check the first two lines, it's activating intl_utils 1.9 > **flutter.bat --no-color pub global activate intl_utils 1.9.0** > **Package intl_utils is currently active at version 2.6.1.** > Resolving dependencies... > + _fe_analyzer_shared 7.0.0 (39.0.0 available) > + analyzer 0.39.17 (4.0.0 available) > + archive 2.0.13 (3.3.0 available) > + args 1.6.0 (2.3.1 available) > + async 2.9.0 > + charcode 1.3.1 > + cli_util 0.2.0 (0.3.5 available) > + collection 1.16.0 > + convert 2.1.1 (3.0.1 available) > + crypto 2.1.5 (3.0.2 available) > + csslib 0.16.2 (0.17.1 available) > + dart_style 1.3.6 (2.2.3 available) > + file 5.2.1 (6.1.2 available) > + glob 1.2.0 (2.0.2 available) > + html 0.14.0+4 (0.15.0 available) > + http 0.12.2 (0.13.4 available) > + http_parser 3.1.4 (4.0.0 available) > + intl 0.16.1 (0.17.0 available) > + intl_translation 0.17.10+1 > + intl_utils 1.9.0 (2.6.1 available) > + js 0.6.4 > + meta 1.7.0 > + node_interop 1.2.1 (2.1.0 available) > + node_io 1.2.0 (2.1.0 available) > + package_config 1.9.3 (2.0.2 available) > + path 1.8.1 > + pedantic 1.11.1 > + petitparser 3.1.0 (5.0.0 available) > + pub_semver 1.4.4 (2.1.1 available) > + source_span 1.9.0 > + string_scanner 1.1.0 > + term_glyph 1.2.0 > + typed_data 1.3.0 > + watcher 0.9.7+15 (1.0.1 available) > + yaml 2.2.1 (3.1.0 available) > Building package executables... > Built intl_utils:localizely_download. > Built intl_utils:localizely_upload_main.
These are my pubspec.yaml settings: > environment: > sdk: '>=2.16.0 <3.0.0' > > flutter_localizations: > sdk: flutter > > flutter_intl: > main_locale: en_US > enabled: true > class_name: AppLocalization > arb_dir: lib/common/localization/l10n > output_dir: lib/common/localization/generated
jonasbark commented 2 years ago

I fixed it by running

flutter pub global activate intl_utils;
flutter --no-color pub global run intl_utils:generate

EDIT: That only really fixed the files but the files generated by this plugin are indeed still invalid.

Charlinjoeaht commented 2 years ago

I am facing the same issue too. The workaround proposed by jonasbark is working for me.

But we have to fix it from the plugin

lzoran commented 2 years ago

I have managed to reproduce this problem.

The Flutter Intl plugin decides which version of the intl_utils to use by looking at the min environment sdk version. If min version is >=2.12.0, it uses intl_utils that generates null-safe code (^2.0.0), otherwise, it uses 1.9.0.

Furthermore, if it fails to check this value for some reason, it checks if the Flutter version starts with 2. And I guess that that is the reason why plugin uses the intl_utils 1.9.0 in some cases.

This will be fixed soon (~ a few days until JetBrains approves it).

In the meantime, could you check if your min environment sdk version is properly formatted, and if not, if formatting it well helps?

The pubspec.yaml file:

environment:
  sdk: ">=2.16.0 <3.0.0" # check indentation and formatting here
rtokun commented 2 years ago

@lzoran Same issue for our project. The formatting of the SDK version is correct.

lzoran commented 2 years ago

The new release of the Flutter Intl plugin (1.17.3) is available and it should fix this issue.

absar commented 2 years ago

Updated plugin works, issue can be closed.