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
95563ff1
Unverified
Commit
95563ff1
authored
Oct 27, 2020
by
Michael Goderbauer
Committed by
GitHub
Oct 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make WidgetsLocalizations.of non-nullable (#69055)
parent
291ee945
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
5 deletions
+73
-5
localizations.dart
packages/flutter/lib/src/cupertino/localizations.dart
+1
-1
material_localizations.dart
...ages/flutter/lib/src/material/material_localizations.dart
+1
-1
debug.dart
packages/flutter/lib/src/widgets/debug.dart
+39
-0
localizations.dart
packages/flutter/lib/src/widgets/localizations.dart
+5
-3
debug_test.dart
packages/flutter/test/widgets/debug_test.dart
+27
-0
No files found.
packages/flutter/lib/src/cupertino/localizations.dart
View file @
95563ff1
...
...
@@ -259,7 +259,7 @@ abstract class CupertinoLocalizations {
/// CupertinoLocalizations.of(context).anteMeridiemAbbreviation;
/// ```
static
CupertinoLocalizations
of
(
BuildContext
context
)
{
debugCheckHasCupertinoLocalizations
(
context
);
assert
(
debugCheckHasCupertinoLocalizations
(
context
)
);
return
Localizations
.
of
<
CupertinoLocalizations
>(
context
,
CupertinoLocalizations
)!;
}
}
...
...
packages/flutter/lib/src/material/material_localizations.dart
View file @
95563ff1
...
...
@@ -506,7 +506,7 @@ abstract class MaterialLocalizations {
/// tooltip: MaterialLocalizations.of(context).backButtonTooltip,
/// ```
static
MaterialLocalizations
of
(
BuildContext
context
)
{
debugCheckHasMaterialLocalizations
(
context
);
assert
(
debugCheckHasMaterialLocalizations
(
context
)
);
return
Localizations
.
of
<
MaterialLocalizations
>(
context
,
MaterialLocalizations
)!;
}
}
...
...
packages/flutter/lib/src/widgets/debug.dart
View file @
95563ff1
...
...
@@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart';
import
'basic.dart'
;
import
'framework.dart'
;
import
'localizations.dart'
;
import
'media_query.dart'
;
import
'table.dart'
;
...
...
@@ -321,6 +322,44 @@ void debugWidgetBuilderValue(Widget widget, Widget? built) {
}());
}
/// Asserts that the given context has a [Localizations] ancestor that contains
/// a [WidgetsLocalizations] delegate.
///
/// To call this function, use the following pattern, typically in the
/// relevant Widget's build method:
///
/// ```dart
/// assert(debugCheckHasWidgetsLocalizations(context));
/// ```
///
/// Does nothing if asserts are disabled. Always returns true.
bool
debugCheckHasWidgetsLocalizations
(
BuildContext
context
)
{
assert
(()
{
if
(
Localizations
.
of
<
WidgetsLocalizations
>(
context
,
WidgetsLocalizations
)
==
null
)
{
throw
FlutterError
.
fromParts
(<
DiagnosticsNode
>[
ErrorSummary
(
'No WidgetsLocalizations found.'
),
ErrorDescription
(
'
${context.widget.runtimeType}
widgets require WidgetsLocalizations '
'to be provided by a Localizations widget ancestor.'
),
ErrorDescription
(
'The widgets library uses Localizations to generate messages, '
'labels, and abbreviations.'
),
ErrorHint
(
'To introduce a WidgetsLocalizations, either use a '
'WidgetsApp at the root of your application to include them '
'automatically, or add a Localization widget with a '
'WidgetsLocalizations delegate.'
),
...
context
.
describeMissingAncestor
(
expectedAncestorType:
WidgetsLocalizations
)
]);
}
return
true
;
}());
return
true
;
}
/// Returns true if none of the widget library debug variables have been changed.
///
/// This function is used by the test framework to ensure that debug variables
...
...
packages/flutter/lib/src/widgets/localizations.dart
View file @
95563ff1
...
...
@@ -10,6 +10,7 @@ import 'package:flutter/rendering.dart';
import
'basic.dart'
;
import
'binding.dart'
;
import
'container.dart'
;
import
'debug.dart'
;
import
'framework.dart'
;
// Examples can assume:
...
...
@@ -155,7 +156,7 @@ abstract class WidgetsLocalizations {
/// that encloses the given context.
///
/// This method is just a convenient shorthand for:
/// `Localizations.of<WidgetsLocalizations>(context, WidgetsLocalizations)`.
/// `Localizations.of<WidgetsLocalizations>(context, WidgetsLocalizations)
!
`.
///
/// References to the localized resources defined by this class are typically
/// written in terms of this method. For example:
...
...
@@ -163,8 +164,9 @@ abstract class WidgetsLocalizations {
/// ```dart
/// textDirection: WidgetsLocalizations.of(context).textDirection,
/// ```
static
WidgetsLocalizations
?
of
(
BuildContext
context
)
{
return
Localizations
.
of
<
WidgetsLocalizations
>(
context
,
WidgetsLocalizations
);
static
WidgetsLocalizations
of
(
BuildContext
context
)
{
assert
(
debugCheckHasWidgetsLocalizations
(
context
));
return
Localizations
.
of
<
WidgetsLocalizations
>(
context
,
WidgetsLocalizations
)!;
}
}
...
...
packages/flutter/test/widgets/debug_test.dart
View file @
95563ff1
...
...
@@ -215,6 +215,33 @@ void main() {
}
});
testWidgets
(
'debugCheckHasWidgetsLocalizations throws'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
noLocalizationsAvailable
=
GlobalKey
();
final
GlobalKey
localizationsAvailable
=
GlobalKey
();
await
tester
.
pumpWidget
(
Container
(
key:
noLocalizationsAvailable
,
child:
WidgetsApp
(
builder:
(
BuildContext
context
,
Widget
?
child
)
{
return
Container
(
key:
localizationsAvailable
,
);
},
color:
const
Color
(
0xFF4CAF50
),
),
),
);
expect
(()
=>
debugCheckHasWidgetsLocalizations
(
noLocalizationsAvailable
.
currentContext
!),
throwsA
(
isAssertionError
.
having
(
(
AssertionError
e
)
=>
e
.
message
,
'message'
,
contains
(
'No WidgetsLocalizations found'
),
)));
expect
(
debugCheckHasWidgetsLocalizations
(
localizationsAvailable
.
currentContext
!),
isTrue
);
});
test
(
'debugAssertAllWidgetVarsUnset'
,
()
{
debugHighlightDeprecatedWidgets
=
true
;
late
FlutterError
error
;
...
...
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