Unverified Commit 56a7dacd authored by Per Classon's avatar Per Classon Committed by GitHub

[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
parent 61c198e7
...@@ -217,19 +217,6 @@ const String lookupFunctionTemplate = ''' ...@@ -217,19 +217,6 @@ const String lookupFunctionTemplate = '''
}'''; }''';
const String lookupFunctionDeferredLoadingTemplate = ''' 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) { Future<@(class)> @(lookupName)(Locale locale) {
@(lookupBody) @(lookupBody)
assert(false, '@(class).delegate failed to load unsupported locale "\$locale"'); assert(false, '@(class).delegate failed to load unsupported locale "\$locale"');
...@@ -243,7 +230,7 @@ const String lookupBodyTemplate = '''@(lookupAllCodesSpecified) ...@@ -243,7 +230,7 @@ const String lookupBodyTemplate = '''@(lookupAllCodesSpecified)
const String switchClauseTemplate = '''case '@(case)': return @(localeClass)();'''; 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)': { const String nestedSwitchTemplate = '''case '@(languageCode)': {
switch (locale.@(code)) { switch (locale.@(code)) {
......
...@@ -1006,7 +1006,7 @@ import 'output-localization-file_zh.dart'; ...@@ -1006,7 +1006,7 @@ import 'output-localization-file_zh.dart';
''')); '''));
}); });
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) fs.currentDirectory.childDirectory('lib').childDirectory('l10n')..createSync(recursive: true)
..childFile(defaultTemplateArbFileName).writeAsStringSync(singleMessageArbFileString); ..childFile(defaultTemplateArbFileName).writeAsStringSync(singleMessageArbFileString);
...@@ -1033,6 +1033,7 @@ import 'output-localization-file_zh.dart'; ...@@ -1033,6 +1033,7 @@ import 'output-localization-file_zh.dart';
''' '''
import 'output-localization-file_en.dart' deferred as output-localization-file_en; import 'output-localization-file_en.dart' deferred as output-localization-file_en;
''')); '''));
expect(localizationsFile, contains('output-localization-file_en.loadLibrary()'));
}); });
group('DateTime tests', () { group('DateTime tests', () {
......
...@@ -94,7 +94,7 @@ class Home extends StatelessWidget { ...@@ -94,7 +94,7 @@ class Home extends StatelessWidget {
final List<String> results = []; final List<String> results = [];
return Row( return Row(
children: <Widget>[ children: <Widget>[
ResultBuilder( LocaleBuilder(
test: 'supportedLocales', test: 'supportedLocales',
callback: (BuildContext context) { callback: (BuildContext context) {
results.add('--- supportedLocales tests ---'); results.add('--- supportedLocales tests ---');
...@@ -254,8 +254,8 @@ class Home extends StatelessWidget { ...@@ -254,8 +254,8 @@ class Home extends StatelessWidget {
]); ]);
}, },
), ),
Builder( LocaleBuilder(
builder: (BuildContext context) { callback: (BuildContext context) {
try { try {
int n = 0; int n = 0;
for (final String result in results) { for (final String result in results) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment