Resolve MaterialApp.locale, WidgetsApp.locale per supportedLocales (#23707)

This commit is contained in:
Hans Muller
2018-10-30 09:53:21 -07:00
committed by GitHub
parent 7217999a9a
commit 06cc1d9ec0
4 changed files with 76 additions and 8 deletions

View File

@@ -107,6 +107,7 @@ void main() {
Widget buildLocaleFrame(Locale locale) {
return buildFrame(
locale: locale,
supportedLocales: <Locale>[locale],
buildContent: (BuildContext context) {
return Localizations.override(
context: context,

View File

@@ -17,6 +17,7 @@ class _TimePickerLauncher extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
locale: locale,
supportedLocales: <Locale>[locale],
localizationsDelegates: GlobalMaterialLocalizations.delegates,
home: Material(
child: Center(

View File

@@ -695,4 +695,54 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('en_US zh_CN'), findsOneWidget);
});
testWidgets('WidgetsApp.locale is resolved against supportedLocales', (WidgetTester tester) async {
// app locale matches a supportedLocale
await tester.pumpWidget(
buildFrame(
supportedLocales: const <Locale>[
Locale('zh', 'CN'),
Locale('en', 'US'),
],
locale: const Locale('en', 'US'),
buildContent: (BuildContext context) {
return Text(Localizations.localeOf(context).toString());
}
)
);
await tester.pumpAndSettle();
expect(find.text('en_US'), findsOneWidget);
// app locale matches a supportedLocale's language
await tester.pumpWidget(
buildFrame(
supportedLocales: const <Locale>[
Locale('zh', 'CN'),
Locale('en', 'GB'),
],
locale: const Locale('en', 'US'),
buildContent: (BuildContext context) {
return Text(Localizations.localeOf(context).toString());
}
)
);
await tester.pumpAndSettle();
expect(find.text('en_GB'), findsOneWidget);
// app locale matches no supportedLocale
await tester.pumpWidget(
buildFrame(
supportedLocales: const <Locale>[
Locale('zh', 'CN'),
Locale('en', 'US'),
],
locale: const Locale('ab', 'CD'),
buildContent: (BuildContext context) {
return Text(Localizations.localeOf(context).toString());
}
)
);
await tester.pumpAndSettle();
expect(find.text('zh_CN'), findsOneWidget);
});
}