From 9f09ff24559fb4fc6804f188703a66468704c149 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Thu, 12 Nov 2020 13:20:13 -0800 Subject: [PATCH] Reland: "Make `PlatformDispatcher.locale` and `locales` return consistent values (#22267)" (#22473) This reverts commit d37b862, relanding #22267, now that flutter/flutter#70252 has landed to prevent the problems it had the first time. Here is the original PR description: For some reason (probably a bad merge on my part), the return values for locale and locales are not the same on web as they are on other platforms for the PlatformDispatcher and SingletonFlutterWindow classes. The web versions are non-nullable and the others are nullable. This converts them to be the same (non-nullable) values --- lib/ui/platform_dispatcher.dart | 16 +++------------- lib/ui/window.dart | 8 ++++---- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index 22dba09c2..091ef928c 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -551,12 +551,7 @@ class PlatformDispatcher { /// /// This is equivalent to `locales.first` and will provide an empty non-null /// locale if the [locales] list has not been set or is empty. - Locale? get locale { - if (locales != null && locales!.isNotEmpty) { - return locales!.first; - } - return null; - } + Locale get locale => locales.first; /// The full system-reported supported locales of the device. /// @@ -573,7 +568,7 @@ class PlatformDispatcher { /// /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to /// observe when this value changes. - List? get locales => configuration.locales; + List get locales => configuration.locales; /// Performs the platform-native locale resolution. /// @@ -649,12 +644,7 @@ class PlatformDispatcher { } // Called from the engine, via hooks.dart - String _localeClosure() { - if (locale == null) { - return ''; - } - return locale.toString(); - } + String _localeClosure() => locale.toString(); /// The lifecycle state immediately after dart isolate initialization. /// diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 4e204e7bf..7c8e514e0 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -340,7 +340,7 @@ class SingletonFlutterWindow extends FlutterWindow { /// /// This is equivalent to `locales.first` and will provide an empty non-null /// locale if the [locales] list has not been set or is empty. - Locale? get locale => platformDispatcher.locale; + Locale get locale => platformDispatcher.locale; /// The full system-reported supported locales of the device. /// @@ -358,7 +358,7 @@ class SingletonFlutterWindow extends FlutterWindow { /// /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to /// observe when this value changes. - List? get locales => platformDispatcher.locales; + List get locales => platformDispatcher.locales; /// Performs the platform-native locale resolution. /// @@ -850,11 +850,11 @@ class Window extends SingletonFlutterWindow { @override // ignore: unnecessary_overrides - Locale? get locale => super.locale; + Locale get locale => super.locale; @override // ignore: unnecessary_overrides - List? get locales => super.locales; + List get locales => super.locales; @override // ignore: unnecessary_overrides -- GitLab