diff --git a/lib/ui/window.dart b/lib/ui/window.dart index c0b6bb9fe861c..1c9399b670eaa 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -475,12 +475,14 @@ class Locale { return true; return other is Locale && other.languageCode == languageCode - && other.scriptCode == scriptCode - && other.countryCode == countryCode; + && other.scriptCode == scriptCode // scriptCode cannot be '' + && (other.countryCode == countryCode // Treat '' as equal to null. + || other.countryCode != null && other.countryCode.isEmpty && countryCode == null + || countryCode != null && countryCode.isEmpty && other.countryCode == null); } @override - int get hashCode => hashValues(languageCode, scriptCode, countryCode); + int get hashCode => hashValues(languageCode, scriptCode, countryCode == '' ? null : countryCode); static Locale _cachedLocale; static String _cachedLocaleString; diff --git a/testing/dart/locale_test.dart b/testing/dart/locale_test.dart index 5bebd5106be6d..64c16db78688b 100644 --- a/testing/dart/locale_test.dart +++ b/testing/dart/locale_test.dart @@ -13,8 +13,6 @@ void main() { expect(const Locale('en').toLanguageTag(), 'en'); expect(const Locale('en'), const Locale('en', $null)); expect(const Locale('en').hashCode, const Locale('en', $null).hashCode); - expect(const Locale('en'), isNot(const Locale('en', ''))); - expect(const Locale('en').hashCode, isNot(const Locale('en', '').hashCode)); expect(const Locale('en', 'US').toLanguageTag(), 'en-US'); expect(const Locale('en', 'US').toString(), 'en_US'); expect(const Locale('iw').toLanguageTag(), 'he'); @@ -52,6 +50,16 @@ void main() { isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn'))); expect(const Locale.fromSubtags(languageCode: 'en').hashCode, isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode)); + + expect(const Locale('en', ''), const Locale('en')); + expect(const Locale('en'), const Locale('en', '')); + expect(const Locale('en'), const Locale('en')); + expect(const Locale('en', ''), const Locale('en', '')); + + expect(const Locale('en', ''), isNot(const Locale('en', 'GB'))); + expect(const Locale('en'), isNot(const Locale('en', 'GB'))); + expect(const Locale('en', 'GB'), isNot(const Locale('en', ''))); + expect(const Locale('en', 'GB'), isNot(const Locale('en'))); }); test('Locale toString does not include separator for \'\'', () {