Skip to content

Commit 56a7dac

Browse files
authored
[flutter_tools] For l10n with deferred loading, use loadLibrary for non-web too (flutter#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
1 parent 61c198e commit 56a7dac

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

dev/tools/localization/gen_l10n_templates.dart

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,6 @@ const String lookupFunctionTemplate = '''
217217
}''';
218218

219219
const String lookupFunctionDeferredLoadingTemplate = '''
220-
/// Lazy load the library for web, on other platforms we return the
221-
/// localizations synchronously.
222-
Future<@(class)> _loadLibraryForWeb(
223-
Future<dynamic> Function() loadLibrary,
224-
@(class) Function() localizationClosure,
225-
) {
226-
if (kIsWeb) {
227-
return loadLibrary().then((dynamic _) => localizationClosure());
228-
} else {
229-
return SynchronousFuture<@(class)>(localizationClosure());
230-
}
231-
}
232-
233220
Future<@(class)> @(lookupName)(Locale locale) {
234221
@(lookupBody)
235222
assert(false, '@(class).delegate failed to load unsupported locale "\$locale"');
@@ -243,7 +230,7 @@ const String lookupBodyTemplate = '''@(lookupAllCodesSpecified)
243230

244231
const String switchClauseTemplate = '''case '@(case)': return @(localeClass)();''';
245232

246-
const String switchClauseDeferredLoadingTemplate = '''case '@(case)': return _loadLibraryForWeb(@(library).loadLibrary, () => @(library).@(localeClass)());''';
233+
const String switchClauseDeferredLoadingTemplate = '''case '@(case)': return @(library).loadLibrary().then((dynamic _) => @(library).@(localeClass)());''';
247234

248235
const String nestedSwitchTemplate = '''case '@(languageCode)': {
249236
switch (locale.@(code)) {

dev/tools/test/localization/gen_l10n_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ import 'output-localization-file_zh.dart';
10061006
'''));
10071007
});
10081008

1009-
test('imports are deferred when useDeferredImports are set', () {
1009+
test('imports are deferred and loaded when useDeferredImports are set', () {
10101010
fs.currentDirectory.childDirectory('lib').childDirectory('l10n')..createSync(recursive: true)
10111011
..childFile(defaultTemplateArbFileName).writeAsStringSync(singleMessageArbFileString);
10121012

@@ -1033,6 +1033,7 @@ import 'output-localization-file_zh.dart';
10331033
'''
10341034
import 'output-localization-file_en.dart' deferred as output-localization-file_en;
10351035
'''));
1036+
expect(localizationsFile, contains('output-localization-file_en.loadLibrary()'));
10361037
});
10371038

10381039
group('DateTime tests', () {

packages/flutter_tools/test/integration.shard/test_data/gen_l10n_project.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Home extends StatelessWidget {
9494
final List<String> results = [];
9595
return Row(
9696
children: <Widget>[
97-
ResultBuilder(
97+
LocaleBuilder(
9898
test: 'supportedLocales',
9999
callback: (BuildContext context) {
100100
results.add('--- supportedLocales tests ---');
@@ -254,8 +254,8 @@ class Home extends StatelessWidget {
254254
]);
255255
},
256256
),
257-
Builder(
258-
builder: (BuildContext context) {
257+
LocaleBuilder(
258+
callback: (BuildContext context) {
259259
try {
260260
int n = 0;
261261
for (final String result in results) {

0 commit comments

Comments
 (0)