Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
06cc1d9e
Unverified
Commit
06cc1d9e
authored
Oct 30, 2018
by
Hans Muller
Committed by
GitHub
Oct 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve MaterialApp.locale, WidgetsApp.locale per supportedLocales (#23707)
parent
7217999a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
8 deletions
+76
-8
app.dart
packages/flutter/lib/src/widgets/app.dart
+24
-8
override_test.dart
packages/flutter_localizations/test/override_test.dart
+1
-0
time_picker_test.dart
packages/flutter_localizations/test/time_picker_test.dart
+1
-0
widgets_test.dart
packages/flutter_localizations/test/widgets_test.dart
+50
-0
No files found.
packages/flutter/lib/src/widgets/app.dart
View file @
06cc1d9e
...
...
@@ -29,9 +29,13 @@ export 'dart:ui' show Locale;
/// [Localizations] object when the app starts and when user changes the default
/// locale for the device.
///
/// The `locale` is the device's locale when the app started, or the device
/// locale the user selected after the app was started. The `supportedLocales`
/// parameter is just the value of [WidgetsApp.supportedLocales].
/// This callback is also used if the app is created with a specific locale using
/// the [new WidgetsApp] `locale` parameter.
///
/// The `locale` is either the value of [WidgetsApp.locale], or the device's
/// locale when the app started, or the device locale the user selected after
/// the app was started. The `supportedLocales` parameter is the value of
/// [WidgetsApp.supportedLocales].
typedef
LocaleResolutionCallback
=
Locale
Function
(
Locale
locale
,
Iterable
<
Locale
>
supportedLocales
);
/// The signature of [WidgetsApp.onGenerateTitle].
...
...
@@ -408,10 +412,22 @@ class WidgetsApp extends StatefulWidget {
final
Color
color
;
/// {@template flutter.widgets.widgetsApp.locale}
/// The initial locale for this app's [Localizations] widget.
/// The initial locale for this app's [Localizations] widget is based
/// on this value.
///
/// If the 'locale' is null then the system's locale value is used.
///
/// If the 'locale' is null the system's locale value is used.
/// The value of [Localizations.locale] will equal this locale if
/// it matches one of the [supportedLocales]. Otherwise it will be
/// the first [supportedLocale].
/// {@endtemplate}
///
/// See also:
///
/// * [localeResolutionCallback], which can override the default
/// [supportedLocales] matching algorithm.
/// * [localizationsDelegates], which collectively define all of the localized
/// resources used by this app.
final
Locale
locale
;
/// {@template flutter.widgets.widgetsApp.localizationsDelegates}
...
...
@@ -467,10 +483,8 @@ class WidgetsApp extends StatefulWidget {
///
/// * [MaterialApp.supportedLocales], which sets the `supportedLocales`
/// of the [WidgetsApp] it creates.
///
/// * [localeResolutionCallback], an app callback that resolves the app's locale
/// when the device's locale changes.
///
/// * [localizationsDelegates], which collectively define all of the localized
/// resources used by this app.
final
Iterable
<
Locale
>
supportedLocales
;
...
...
@@ -863,7 +877,9 @@ class _WidgetsAppState extends State<WidgetsApp> implements WidgetsBindingObserv
return
MediaQuery
(
data:
MediaQueryData
.
fromWindow
(
ui
.
window
),
child:
Localizations
(
locale:
widget
.
locale
??
_locale
,
locale:
widget
.
locale
!=
null
?
_resolveLocale
(
widget
.
locale
,
widget
.
supportedLocales
)
:
_locale
,
delegates:
_localizationsDelegates
.
toList
(),
child:
title
,
),
...
...
packages/flutter_localizations/test/override_test.dart
View file @
06cc1d9e
...
...
@@ -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
,
...
...
packages/flutter_localizations/test/time_picker_test.dart
View file @
06cc1d9e
...
...
@@ -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
(
...
...
packages/flutter_localizations/test/widgets_test.dart
View file @
06cc1d9e
...
...
@@ -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
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment