Unverified Commit dfd02295 authored by Gary Qian's avatar Gary Qian Committed by GitHub

New locale resolution algorithm to use full preferred locale list, include...

New locale resolution algorithm to use full preferred locale list, include scriptCode in Locale. (#23583)
parent 5071657e
......@@ -90,6 +90,7 @@ class CupertinoApp extends StatefulWidget {
this.color,
this.locale,
this.localizationsDelegates,
this.localeListResolutionCallback,
this.localeResolutionCallback,
this.supportedLocales = const <Locale>[Locale('en', 'US')],
this.showPerformanceOverlay = false,
......@@ -157,6 +158,11 @@ class CupertinoApp extends StatefulWidget {
/// {@macro flutter.widgets.widgetsApp.localizationsDelegates}
final Iterable<LocalizationsDelegate<dynamic>> localizationsDelegates;
/// {@macro flutter.widgets.widgetsApp.localeListResolutionCallback}
///
/// This callback is passed along to the [WidgetsApp] built by this widget.
final LocaleListResolutionCallback localeListResolutionCallback;
/// {@macro flutter.widgets.widgetsApp.localeResolutionCallback}
///
/// This callback is passed along to the [WidgetsApp] built by this widget.
......@@ -283,6 +289,7 @@ class _CupertinoAppState extends State<CupertinoApp> {
locale: widget.locale,
localizationsDelegates: _localizationsDelegates,
localeResolutionCallback: widget.localeResolutionCallback,
localeListResolutionCallback: widget.localeListResolutionCallback,
supportedLocales: widget.supportedLocales,
showPerformanceOverlay: widget.showPerformanceOverlay,
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
......
......@@ -98,6 +98,7 @@ class MaterialApp extends StatefulWidget {
this.theme,
this.locale,
this.localizationsDelegates,
this.localeListResolutionCallback,
this.localeResolutionCallback,
this.supportedLocales = const <Locale>[Locale('en', 'US')],
this.debugShowMaterialGrid = false,
......@@ -264,6 +265,11 @@ class MaterialApp extends StatefulWidget {
/// <https://flutter.io/tutorials/internationalization/>.
final Iterable<LocalizationsDelegate<dynamic>> localizationsDelegates;
/// {@macro flutter.widgets.widgetsApp.localeListResolutionCallback}
///
/// This callback is passed along to the [WidgetsApp] built by this widget.
final LocaleListResolutionCallback localeListResolutionCallback;
/// {@macro flutter.widgets.widgetsApp.localeResolutionCallback}
///
/// This callback is passed along to the [WidgetsApp] built by this widget.
......@@ -423,6 +429,7 @@ class _MaterialAppState extends State<MaterialApp> {
locale: widget.locale,
localizationsDelegates: _localizationsDelegates,
localeResolutionCallback: widget.localeResolutionCallback,
localeListResolutionCallback: widget.localeListResolutionCallback,
supportedLocales: widget.supportedLocales,
showPerformanceOverlay: widget.showPerformanceOverlay,
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
......
This diff is collapsed.
......@@ -219,7 +219,7 @@ abstract class WidgetsBindingObserver {
/// settings.
///
/// This method exposes notifications from [Window.onLocaleChanged].
void didChangeLocale(Locale locale) { }
void didChangeLocales(List<Locale> locale) { }
/// Called when the system puts the app in the background or returns
/// the app to the foreground.
......@@ -413,20 +413,20 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB
@protected
@mustCallSuper
void handleLocaleChanged() {
dispatchLocaleChanged(ui.window.locale);
dispatchLocalesChanged(ui.window.locales);
}
/// Notify all the observers that the locale has changed (using
/// [WidgetsBindingObserver.didChangeLocale]), giving them the
/// `locale` argument.
/// [WidgetsBindingObserver.didChangeLocales]), giving them the
/// `locales` argument.
///
/// This is called by [handleLocaleChanged] when the [Window.onLocaleChanged]
/// notification is received.
@protected
@mustCallSuper
void dispatchLocaleChanged(Locale locale) {
void dispatchLocalesChanged(List<Locale> locales) {
for (WidgetsBindingObserver observer in _observers)
observer.didChangeLocale(locale);
observer.didChangeLocales(locales);
}
/// Notify all the observers that the active set of [AccessibilityFeatures]
......
......@@ -225,13 +225,25 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
Duration additionalTime = const Duration(milliseconds: 250),
});
/// Artificially calls dispatchLocaleChanged on the Widget binding,
/// Artificially calls dispatchLocalesChanged on the Widget binding,
/// then flushes microtasks.
///
/// Passes only one single Locale. Use [setLocales] to pass a full preferred
/// locales list.
Future<void> setLocale(String languageCode, String countryCode) {
return TestAsyncUtils.guard<void>(() async {
assert(inTest);
final Locale locale = Locale(languageCode, countryCode);
dispatchLocaleChanged(locale);
final Locale locale = Locale(languageCode, countryCode == '' ? null : countryCode);
dispatchLocalesChanged(<Locale>[locale]);
});
}
/// Artificially calls dispatchLocalesChanged on the Widget binding,
/// then flushes microtasks.
Future<void> setLocales(List<Locale> locales) {
return TestAsyncUtils.guard<void>(() async {
assert(inTest);
dispatchLocalesChanged(locales);
});
}
......
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