[flutter_tools] For l10n with deferred loading, use loadLibrary for non-web too (#59539)
After Dart VM change we are now required to use loadLibrary on an import whenever it is imported as deferred.
See: https://dart-review.googlesource.com/c/sdk/+/149613
diff --git a/dev/tools/localization/gen_l10n_templates.dart b/dev/tools/localization/gen_l10n_templates.dart
index 41a0e7d..cfef475 100644
--- a/dev/tools/localization/gen_l10n_templates.dart
+++ b/dev/tools/localization/gen_l10n_templates.dart
@@ -217,19 +217,6 @@
}''';
const String lookupFunctionDeferredLoadingTemplate = '''
-/// Lazy load the library for web, on other platforms we return the
-/// localizations synchronously.
-Future<@(class)> _loadLibraryForWeb(
- Future<dynamic> Function() loadLibrary,
- @(class) Function() localizationClosure,
-) {
- if (kIsWeb) {
- return loadLibrary().then((dynamic _) => localizationClosure());
- } else {
- return SynchronousFuture<@(class)>(localizationClosure());
- }
-}
-
Future<@(class)> @(lookupName)(Locale locale) {
@(lookupBody)
assert(false, '@(class).delegate failed to load unsupported locale "\$locale"');
@@ -243,7 +230,7 @@
const String switchClauseTemplate = '''case '@(case)': return @(localeClass)();''';
-const String switchClauseDeferredLoadingTemplate = '''case '@(case)': return _loadLibraryForWeb(@(library).loadLibrary, () => @(library).@(localeClass)());''';
+const String switchClauseDeferredLoadingTemplate = '''case '@(case)': return @(library).loadLibrary().then((dynamic _) => @(library).@(localeClass)());''';
const String nestedSwitchTemplate = '''case '@(languageCode)': {
switch (locale.@(code)) {
diff --git a/dev/tools/test/localization/gen_l10n_test.dart b/dev/tools/test/localization/gen_l10n_test.dart
index ad6943f..b055857 100644
--- a/dev/tools/test/localization/gen_l10n_test.dart
+++ b/dev/tools/test/localization/gen_l10n_test.dart
@@ -1006,7 +1006,7 @@
'''));
});
- test('imports are deferred when useDeferredImports are set', () {
+ test('imports are deferred and loaded when useDeferredImports are set', () {
fs.currentDirectory.childDirectory('lib').childDirectory('l10n')..createSync(recursive: true)
..childFile(defaultTemplateArbFileName).writeAsStringSync(singleMessageArbFileString);
@@ -1033,6 +1033,7 @@
'''
import 'output-localization-file_en.dart' deferred as output-localization-file_en;
'''));
+ expect(localizationsFile, contains('output-localization-file_en.loadLibrary()'));
});
group('DateTime tests', () {
diff --git a/packages/flutter_tools/test/integration.shard/test_data/gen_l10n_project.dart b/packages/flutter_tools/test/integration.shard/test_data/gen_l10n_project.dart
index 2333205..103d700 100644
--- a/packages/flutter_tools/test/integration.shard/test_data/gen_l10n_project.dart
+++ b/packages/flutter_tools/test/integration.shard/test_data/gen_l10n_project.dart
@@ -94,7 +94,7 @@
final List<String> results = [];
return Row(
children: <Widget>[
- ResultBuilder(
+ LocaleBuilder(
test: 'supportedLocales',
callback: (BuildContext context) {
results.add('--- supportedLocales tests ---');
@@ -254,8 +254,8 @@
]);
},
),
- Builder(
- builder: (BuildContext context) {
+ LocaleBuilder(
+ callback: (BuildContext context) {
try {
int n = 0;
for (final String result in results) {