From 02d659e82ae88fbe7439c9679a5094795afbae04 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Tue, 23 Oct 2018 13:57:43 -0700 Subject: [PATCH] Support null locale before locale initialization, Roll engine to cdd592f5be97e824 (#23417) cdd592f5b Reland 'Pass null instead of 'none' locale' (#6632) 2cd89200c Roll src/third_party/skia b1a002e850e1..327955b1ba19 (12 commits) (#6631) edfe02481 13771 - iOS dictation bug (#6607) cadf4405b Roll src/third_party/skia b9998cdceec7..b1a002e850e1 (13 commits) (#6626) --- bin/internal/engine.version | 2 +- bin/internal/goldens.version | 2 +- packages/flutter/lib/src/widgets/app.dart | 8 +++++--- .../test/widgets_test.dart | 17 ++++++++++------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/bin/internal/engine.version b/bin/internal/engine.version index 6c3c7fadbc..15fb23e2a9 100644 --- a/bin/internal/engine.version +++ b/bin/internal/engine.version @@ -1 +1 @@ -4c79e423dc6f89f98d8ceb263a5ca78e2f2da996 +cdd592f5be97e8245b31d7621bc95234b62c3a43 diff --git a/bin/internal/goldens.version b/bin/internal/goldens.version index 754ef3ec41..a4aae1372f 100644 --- a/bin/internal/goldens.version +++ b/bin/internal/goldens.version @@ -1 +1 @@ -2a4133039bc4f59613a73a6d871a7c0e6f2396fa +afef1dc571f94a41751917d3946defba782335f7 diff --git a/packages/flutter/lib/src/widgets/app.dart b/packages/flutter/lib/src/widgets/app.dart index 15c9de9ed5..af00037a1f 100644 --- a/packages/flutter/lib/src/widgets/app.dart +++ b/packages/flutter/lib/src/widgets/app.dart @@ -678,14 +678,16 @@ class _WidgetsAppState extends State implements WidgetsBindingObserv Locale _locale; Locale _resolveLocale(Locale newLocale, Iterable supportedLocales) { - if (newLocale == null) { - return supportedLocales.first; - } if (widget.localeResolutionCallback != null) { final Locale locale = widget.localeResolutionCallback(newLocale, widget.supportedLocales); if (locale != null) return locale; } + // newLocale can be null when called before the platform has had a chance to + // initialize the locales. We default to the first supported locale. + if (newLocale == null) { + return supportedLocales.first; + } Locale matchesLanguageCode; for (Locale locale in supportedLocales) { diff --git a/packages/flutter_localizations/test/widgets_test.dart b/packages/flutter_localizations/test/widgets_test.dart index efc8fc6aba..1a2923f07c 100644 --- a/packages/flutter_localizations/test/widgets_test.dart +++ b/packages/flutter_localizations/test/widgets_test.dart @@ -537,7 +537,7 @@ void main() { ) ); - // Startup time. Default test locale is const Locale('', ''), so + // Startup time. Default test locale is null, so // no supported matches. Use the first locale. await tester.pumpAndSettle(); expect(find.text('zh_CN'), findsOneWidget); @@ -581,9 +581,10 @@ void main() { ) ); - // Initial WidgetTester locale is new Locale('', '') + // Initial WidgetTester locale is null due to no platform intitializing it. + // The locale gets resolved to "en_US", which is the first supported locale. await tester.pumpAndSettle(); - expect(find.text('_ TextDirection.ltr'), findsOneWidget); + expect(find.text('en_US TextDirection.ltr'), findsOneWidget); await tester.binding.setLocale('en', 'CA'); await tester.pumpAndSettle(); @@ -622,9 +623,10 @@ void main() { ) ); - // Initial WidgetTester locale is new Locale('', '') + // Initial WidgetTester locale is null due to no platform intitializing it. + // The locale gets resolved to "en_US", which is the first supported locale. await tester.pumpAndSettle(); - expect(find.text('_ TextDirection.rtl'), findsOneWidget); + expect(find.text('en_US TextDirection.rtl'), findsOneWidget); await tester.binding.setLocale('en', 'CA'); await tester.pumpAndSettle(); @@ -655,9 +657,10 @@ void main() { ) ); - // Initial WidgetTester locale is new Locale('', '') + // Initial WidgetTester locale is null due to no platform intitializing it. + // The locale gets resolved to "en_US", which is the first supported locale. await tester.pumpAndSettle(); - expect(find.text('_ TextDirection.rtl'), findsOneWidget); + expect(find.text('en_US TextDirection.rtl'), findsOneWidget); await tester.binding.setLocale('en', 'CA'); await tester.pumpAndSettle();