diff --git a/packages/flutter_localizations/lib/src/material_localizations.dart b/packages/flutter_localizations/lib/src/material_localizations.dart index 05cb477d9c..1c9a640c88 100644 --- a/packages/flutter_localizations/lib/src/material_localizations.dart +++ b/packages/flutter_localizations/lib/src/material_localizations.dart @@ -133,8 +133,7 @@ class GlobalMaterialLocalizations implements MaterialLocalizations { intl.DateFormat _yearMonthFormat; static String _computeLocaleName(Locale locale) { - final String localeName = locale.countryCode.isEmpty ? locale.languageCode : locale.toString(); - return intl.Intl.canonicalizedLocale(localeName); + return intl.Intl.canonicalizedLocale(locale.toString()); } @override diff --git a/packages/flutter_localizations/test/basics_test.dart b/packages/flutter_localizations/test/basics_test.dart index da81575e9c..18c41a041f 100644 --- a/packages/flutter_localizations/test/basics_test.dart +++ b/packages/flutter_localizations/test/basics_test.dart @@ -47,6 +47,28 @@ void main() { await tester.pump(); await tester.pumpWidget(new Container()); }); + + testWidgets('Locale without coutryCode', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/pull/16782 + await tester.pumpWidget( + new MaterialApp( + localizationsDelegates: const >[ + GlobalMaterialLocalizations.delegate, + ], + supportedLocales: const [ + const Locale('es', 'ES'), + const Locale('zh'), + ], + home: new Container(), + ) + ); + + await tester.binding.setLocale('zh', null); + await tester.pump(); + await tester.binding.setLocale('es', 'US'); + await tester.pump(); + + }); } /// A localizations delegate that does not contain any useful data, and is only