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
9d2037e9
Commit
9d2037e9
authored
Nov 19, 2018
by
Noor Dawod
Committed by
Gary Qian
Nov 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for empty and null preferredLocales before passing to 'localeResolutionCallback'. (#24481)
parent
ec4f22c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletion
+41
-1
app.dart
packages/flutter/lib/src/widgets/app.dart
+4
-1
widgets_test.dart
packages/flutter_localizations/test/widgets_test.dart
+37
-0
No files found.
packages/flutter/lib/src/widgets/app.dart
View file @
9d2037e9
...
...
@@ -810,7 +810,10 @@ class _WidgetsAppState extends State<WidgetsApp> implements WidgetsBindingObserv
}
// localeListResolutionCallback failed, falling back to localeResolutionCallback.
if
(
widget
.
localeResolutionCallback
!=
null
)
{
final
Locale
locale
=
widget
.
localeResolutionCallback
(
preferredLocales
.
first
,
widget
.
supportedLocales
);
final
Locale
locale
=
widget
.
localeResolutionCallback
(
preferredLocales
!=
null
&&
preferredLocales
.
isNotEmpty
?
preferredLocales
.
first
:
null
,
widget
.
supportedLocales
,
);
if
(
locale
!=
null
)
return
locale
;
}
...
...
packages/flutter_localizations/test/widgets_test.dart
View file @
9d2037e9
...
...
@@ -1414,4 +1414,41 @@ void main() {
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'en_CA'
),
findsOneWidget
);
});
testWidgets
(
'WidgetsApp invalid preferredLocales'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
buildFrame
(
supportedLocales:
const
<
Locale
>[
Locale
(
'zh'
,
'CN'
),
Locale
(
'en'
,
'CA'
),
Locale
(
'en'
,
'US'
),
Locale
(
'en'
,
'AU'
),
Locale
(
'de'
,
'DE'
),
],
localeResolutionCallback:
(
Locale
locale
,
Iterable
<
Locale
>
supportedLocales
)
{
if
(
locale
==
null
)
return
const
Locale
(
'und'
,
'US'
);
return
const
Locale
(
'en'
,
'US'
);
},
buildContent:
(
BuildContext
context
)
{
final
Locale
locale
=
Localizations
.
localeOf
(
context
);
return
Text
(
'
$locale
'
);
}
)
);
await
tester
.
binding
.
setLocales
(
const
<
Locale
>[
Locale
.
fromSubtags
(
languageCode:
'en'
,
countryCode:
'US'
),]
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'en_US'
),
findsOneWidget
);
await
tester
.
binding
.
setLocales
(
null
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'und_US'
),
findsOneWidget
);
await
tester
.
binding
.
setLocales
(
const
<
Locale
>[]);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'und_US'
),
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