localizely/intl_utils

Generate files without null safety when using Dart 2.11 or lower

Closed this issue · 1 comments

Hello,
since many big apps are going to take a while to migrate all their dependencies to null safety versions, it would be nice to generate the localization files while in compatibility mode.
At the moment, running the following command with Flutter 2.0, intl_utils 2.0.0 and Dart SDK constraint >=2.11, it throws an error:

flutter pub run --no-sound-null-safety intl_utils:generate

Error in parsing /****/lib/generated/l10n.dart, no messages extracted.
ERROR: Failed to generate localization files.
Invalid argument(s): Parsing errors in /****/lib/generated/l10n.dart
pub finished with exit code 2

The parsing error seems to be that the l10n.dart file generates a nullable variable:

static AppLocalizations? current;

I believe this is fixable. There are other generator packages that can be run in this "compatibility" mode. moor_generator or built_value are an example. I think the analyzer package has the capability to check the environment in which it is being executed.

After some thought, maybe it is better to keep the null safe version. Otherwise the maintainability will get harder.
One of the reasons for raising up the issue was to try to avoid so many dependency overrides when using version under 2.0.0.

If any one needs a version that generates non null safe code during its project transition period, he can use my fork:

intl_utils: 
    git:
      url: https://www.github.com/davidmartos96/intl_utils.git
      ref: compat