[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
This commit is contained in:
Per Classon
2020-06-16 22:36:28 +02:00
committed by GitHub
parent 61c198e766
commit 56a7dacd46
3 changed files with 6 additions and 18 deletions

View File

@@ -217,19 +217,6 @@ const String lookupFunctionTemplate = '''
}''';
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 lookupBodyTemplate = '''@(lookupAllCodesSpecified)
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)) {

View File

@@ -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)
..childFile(defaultTemplateArbFileName).writeAsStringSync(singleMessageArbFileString);
@@ -1033,6 +1033,7 @@ import 'output-localization-file_zh.dart';
'''
import 'output-localization-file_en.dart' deferred as output-localization-file_en;
'''));
expect(localizationsFile, contains('output-localization-file_en.loadLibrary()'));
});
group('DateTime tests', () {

View File

@@ -94,7 +94,7 @@ class Home extends StatelessWidget {
final List<String> results = [];
return Row(
children: <Widget>[
ResultBuilder(
LocaleBuilder(
test: 'supportedLocales',
callback: (BuildContext context) {
results.add('--- supportedLocales tests ---');
@@ -254,8 +254,8 @@ class Home extends StatelessWidget {
]);
},
),
Builder(
builder: (BuildContext context) {
LocaleBuilder(
callback: (BuildContext context) {
try {
int n = 0;
for (final String result in results) {