Commit 286cd359 authored by 血心's avatar 血心 Committed by Hans Muller

Fix bug for calling isEmpty on null object. (#16782)

parent ff58db4a
...@@ -133,8 +133,7 @@ class GlobalMaterialLocalizations implements MaterialLocalizations { ...@@ -133,8 +133,7 @@ class GlobalMaterialLocalizations implements MaterialLocalizations {
intl.DateFormat _yearMonthFormat; intl.DateFormat _yearMonthFormat;
static String _computeLocaleName(Locale locale) { static String _computeLocaleName(Locale locale) {
final String localeName = locale.countryCode.isEmpty ? locale.languageCode : locale.toString(); return intl.Intl.canonicalizedLocale(locale.toString());
return intl.Intl.canonicalizedLocale(localeName);
} }
@override @override
......
...@@ -47,6 +47,28 @@ void main() { ...@@ -47,6 +47,28 @@ void main() {
await tester.pump(); await tester.pump();
await tester.pumpWidget(new Container()); 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 <LocalizationsDelegate<dynamic>>[
GlobalMaterialLocalizations.delegate,
],
supportedLocales: const <Locale>[
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 /// A localizations delegate that does not contain any useful data, and is only
......
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