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
0cf1b407
Unverified
Commit
0cf1b407
authored
Sep 17, 2020
by
Alexandre Ardhuin
Committed by
GitHub
Sep 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove non-nullability on Navigator methods (#65997)
parent
ca12929c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
21 deletions
+49
-21
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+22
-21
navigator_test.dart
packages/flutter/test/widgets/navigator_test.dart
+27
-0
No files found.
packages/flutter/lib/src/widgets/navigator.dart
View file @
0cf1b407
...
...
@@ -1616,7 +1616,7 @@ class Navigator extends StatefulWidget {
/// ```
/// {@end-tool}
@optionalTypeArgs
static
Future
<
T
>
pushNamed
<
T
extends
Object
>(
static
Future
<
T
>
pushNamed
<
T
extends
Object
?
>(
BuildContext
context
,
String
routeName
,
{
Object
?
arguments
,
...
...
@@ -1673,7 +1673,7 @@ class Navigator extends StatefulWidget {
/// ```
/// {@end-tool}
@optionalTypeArgs
static
Future
<
T
>
pushReplacementNamed
<
T
extends
Object
,
TO
extends
Object
>(
static
Future
<
T
>
pushReplacementNamed
<
T
extends
Object
?,
TO
extends
Object
?
>(
BuildContext
context
,
String
routeName
,
{
TO
?
result
,
...
...
@@ -1726,7 +1726,7 @@ class Navigator extends StatefulWidget {
/// ```
/// {@end-tool}
@optionalTypeArgs
static
Future
<
T
>
popAndPushNamed
<
T
extends
Object
,
TO
extends
Object
>(
static
Future
<
T
>
popAndPushNamed
<
T
extends
Object
?,
TO
extends
Object
?
>(
BuildContext
context
,
String
routeName
,
{
TO
?
result
,
...
...
@@ -1790,7 +1790,7 @@ class Navigator extends StatefulWidget {
/// ```
/// {@end-tool}
@optionalTypeArgs
static
Future
<
T
>
pushNamedAndRemoveUntil
<
T
extends
Object
>(
static
Future
<
T
>
pushNamedAndRemoveUntil
<
T
extends
Object
?
>(
BuildContext
context
,
String
newRouteName
,
RoutePredicate
predicate
,
{
...
...
@@ -1828,7 +1828,7 @@ class Navigator extends StatefulWidget {
/// ```
/// {@end-tool}
@optionalTypeArgs
static
Future
<
T
>
push
<
T
extends
Object
>(
BuildContext
context
,
Route
<
T
>
route
)
{
static
Future
<
T
>
push
<
T
extends
Object
?
>(
BuildContext
context
,
Route
<
T
>
route
)
{
return
Navigator
.
of
(
context
)!.
push
(
route
);
}
...
...
@@ -1872,7 +1872,7 @@ class Navigator extends StatefulWidget {
/// ```
/// {@end-tool}
@optionalTypeArgs
static
Future
<
T
>
pushReplacement
<
T
extends
Object
,
TO
extends
Object
>(
BuildContext
context
,
Route
<
T
>
newRoute
,
{
TO
?
result
})
{
static
Future
<
T
>
pushReplacement
<
T
extends
Object
?,
TO
extends
Object
?
>(
BuildContext
context
,
Route
<
T
>
newRoute
,
{
TO
?
result
})
{
return
Navigator
.
of
(
context
)!.
pushReplacement
<
T
,
TO
>(
newRoute
,
result:
result
);
}
...
...
@@ -1926,7 +1926,7 @@ class Navigator extends StatefulWidget {
/// ```
/// {@end-tool}
@optionalTypeArgs
static
Future
<
T
>
pushAndRemoveUntil
<
T
extends
Object
>(
BuildContext
context
,
Route
<
T
>
newRoute
,
RoutePredicate
predicate
)
{
static
Future
<
T
>
pushAndRemoveUntil
<
T
extends
Object
?
>(
BuildContext
context
,
Route
<
T
>
newRoute
,
RoutePredicate
predicate
)
{
return
Navigator
.
of
(
context
)!.
pushAndRemoveUntil
<
T
>(
newRoute
,
predicate
);
}
...
...
@@ -1962,7 +1962,7 @@ class Navigator extends StatefulWidget {
/// * [replaceRouteBelow], which is the same but identifies the route to be
/// removed by reference to the route above it, rather than directly.
@optionalTypeArgs
static
void
replace
<
T
extends
Object
>(
BuildContext
context
,
{
required
Route
<
dynamic
>
oldRoute
,
required
Route
<
T
>
newRoute
})
{
static
void
replace
<
T
extends
Object
?
>(
BuildContext
context
,
{
required
Route
<
dynamic
>
oldRoute
,
required
Route
<
T
>
newRoute
})
{
return
Navigator
.
of
(
context
)!.
replace
<
T
>(
oldRoute:
oldRoute
,
newRoute:
newRoute
);
}
...
...
@@ -1996,7 +1996,7 @@ class Navigator extends StatefulWidget {
/// * [replace], which is the same but identifies the route to be removed
/// directly.
@optionalTypeArgs
static
void
replaceRouteBelow
<
T
extends
Object
>(
BuildContext
context
,
{
required
Route
<
dynamic
>
anchorRoute
,
required
Route
<
T
>
newRoute
})
{
static
void
replaceRouteBelow
<
T
extends
Object
?
>(
BuildContext
context
,
{
required
Route
<
dynamic
>
anchorRoute
,
required
Route
<
T
>
newRoute
})
{
return
Navigator
.
of
(
context
)!.
replaceRouteBelow
<
T
>(
anchorRoute:
anchorRoute
,
newRoute:
newRoute
);
}
...
...
@@ -2051,7 +2051,7 @@ class Navigator extends StatefulWidget {
/// * [ModalRoute], which provides a `scopedWillPopCallback` that can be used
/// to define the route's `willPop` method.
@optionalTypeArgs
static
Future
<
bool
>
maybePop
<
T
extends
Object
>(
BuildContext
context
,
[
T
?
result
])
{
static
Future
<
bool
>
maybePop
<
T
extends
Object
?
>(
BuildContext
context
,
[
T
?
result
])
{
return
Navigator
.
of
(
context
)!.
maybePop
<
T
>(
result
);
}
...
...
@@ -2101,7 +2101,7 @@ class Navigator extends StatefulWidget {
/// }
/// ```
@optionalTypeArgs
static
void
pop
<
T
extends
Object
>(
BuildContext
context
,
[
T
?
result
])
{
static
void
pop
<
T
extends
Object
?
>(
BuildContext
context
,
[
T
?
result
])
{
Navigator
.
of
(
context
)!.
pop
<
T
>(
result
);
}
...
...
@@ -3456,7 +3456,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// ```
/// {@end-tool}
@optionalTypeArgs
Future
<
T
>
pushNamed
<
T
extends
Object
>(
Future
<
T
>
pushNamed
<
T
extends
Object
?
>(
String
routeName
,
{
Object
?
arguments
,
})
{
...
...
@@ -3482,7 +3482,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// ```
/// {@end-tool}
@optionalTypeArgs
Future
<
T
>
pushReplacementNamed
<
T
extends
Object
,
TO
extends
Object
>(
Future
<
T
>
pushReplacementNamed
<
T
extends
Object
?,
TO
extends
Object
?
>(
String
routeName
,
{
TO
?
result
,
Object
?
arguments
,
...
...
@@ -3508,7 +3508,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// ```
/// {@end-tool}
@optionalTypeArgs
Future
<
T
>
popAndPushNamed
<
T
extends
Object
,
TO
extends
Object
>(
Future
<
T
>
popAndPushNamed
<
T
extends
Object
?,
TO
extends
Object
?
>(
String
routeName
,
{
TO
?
result
,
Object
?
arguments
,
...
...
@@ -3535,7 +3535,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// ```
/// {@end-tool}
@optionalTypeArgs
Future
<
T
>
pushNamedAndRemoveUntil
<
T
extends
Object
>(
Future
<
T
>
pushNamedAndRemoveUntil
<
T
extends
Object
?
>(
String
newRouteName
,
RoutePredicate
predicate
,
{
Object
?
arguments
,
...
...
@@ -3633,7 +3633,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// ```
/// {@end-tool}
@optionalTypeArgs
Future
<
T
>
pushReplacement
<
T
extends
Object
,
TO
extends
Object
>(
Route
<
T
>
newRoute
,
{
TO
?
result
})
{
Future
<
T
>
pushReplacement
<
T
extends
Object
?,
TO
extends
Object
?
>(
Route
<
T
>
newRoute
,
{
TO
?
result
})
{
assert
(!
_debugLocked
);
assert
(()
{
_debugLocked
=
true
;
...
...
@@ -3673,7 +3673,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// ```
/// {@end-tool}
@optionalTypeArgs
Future
<
T
>
pushAndRemoveUntil
<
T
extends
Object
>(
Route
<
T
>
newRoute
,
RoutePredicate
predicate
)
{
Future
<
T
>
pushAndRemoveUntil
<
T
extends
Object
?
>(
Route
<
T
>
newRoute
,
RoutePredicate
predicate
)
{
assert
(!
_debugLocked
);
assert
(()
{
_debugLocked
=
true
;
...
...
@@ -3709,7 +3709,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// * [replaceRouteBelow], which is the same but identifies the route to be
/// removed by reference to the route above it, rather than directly.
@optionalTypeArgs
void
replace
<
T
extends
Object
>({
required
Route
<
dynamic
>
oldRoute
,
required
Route
<
T
>
newRoute
})
{
void
replace
<
T
extends
Object
?
>({
required
Route
<
dynamic
>
oldRoute
,
required
Route
<
T
>
newRoute
})
{
assert
(!
_debugLocked
);
assert
(
oldRoute
!=
null
);
assert
(
newRoute
!=
null
);
...
...
@@ -3746,7 +3746,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// * [replace], which is the same but identifies the route to be removed
/// directly.
@optionalTypeArgs
void
replaceRouteBelow
<
T
extends
Object
>({
required
Route
<
dynamic
>
anchorRoute
,
required
Route
<
T
>
newRoute
})
{
void
replaceRouteBelow
<
T
extends
Object
?
>({
required
Route
<
dynamic
>
anchorRoute
,
required
Route
<
T
>
newRoute
})
{
assert
(!
_debugLocked
);
assert
(()
{
_debugLocked
=
true
;
return
true
;
}());
assert
(
anchorRoute
!=
null
);
...
...
@@ -3800,7 +3800,8 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// to veto a [pop] initiated by the app's back button.
/// * [ModalRoute], which provides a `scopedWillPopCallback` that can be used
/// to define the route's `willPop` method.
Future
<
bool
>
maybePop
<
T
extends
Object
>([
T
?
result
])
async
{
@optionalTypeArgs
Future
<
bool
>
maybePop
<
T
extends
Object
?>([
T
?
result
])
async
{
final
_RouteEntry
?
lastEntry
=
_history
.
cast
<
_RouteEntry
?>().
lastWhere
(
(
_RouteEntry
?
e
)
=>
e
!=
null
&&
_RouteEntry
.
isPresentPredicate
(
e
),
orElse:
()
=>
null
,
...
...
@@ -3854,7 +3855,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
/// ```
/// {@end-tool}
@optionalTypeArgs
void
pop
<
T
extends
Object
>([
T
?
result
])
{
void
pop
<
T
extends
Object
?
>([
T
?
result
])
{
assert
(!
_debugLocked
);
assert
(()
{
_debugLocked
=
true
;
...
...
packages/flutter/test/widgets/navigator_test.dart
View file @
0cf1b407
...
...
@@ -343,6 +343,33 @@ void main() {
expect
(
find
.
text
(
'B'
),
findsOneWidget
);
});
testWidgets
(
'popAndPushNamed with explicit void type parameter'
,
(
WidgetTester
tester
)
async
{
final
Map
<
String
,
WidgetBuilder
>
routes
=
<
String
,
WidgetBuilder
>{
'/'
:
(
BuildContext
context
)
=>
OnTapPage
(
id:
'/'
,
onTap:
()
{
Navigator
.
pushNamed
<
void
>(
context
,
'/A'
);
}),
'/A'
:
(
BuildContext
context
)
=>
OnTapPage
(
id:
'A'
,
onTap:
()
{
Navigator
.
popAndPushNamed
<
void
,
void
>(
context
,
'/B'
);
}),
'/B'
:
(
BuildContext
context
)
=>
OnTapPage
(
id:
'B'
,
onTap:
()
{
Navigator
.
pop
<
void
>(
context
);
}),
};
await
tester
.
pumpWidget
(
MaterialApp
(
routes:
routes
));
expect
(
find
.
text
(
'/'
),
findsOneWidget
);
expect
(
find
.
text
(
'A'
,
skipOffstage:
false
),
findsNothing
);
expect
(
find
.
text
(
'B'
,
skipOffstage:
false
),
findsNothing
);
await
tester
.
tap
(
find
.
text
(
'/'
));
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
find
.
text
(
'/'
),
findsNothing
);
expect
(
find
.
text
(
'A'
),
findsOneWidget
);
expect
(
find
.
text
(
'B'
),
findsNothing
);
await
tester
.
tap
(
find
.
text
(
'A'
));
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
find
.
text
(
'/'
),
findsNothing
);
expect
(
find
.
text
(
'A'
),
findsNothing
);
expect
(
find
.
text
(
'B'
),
findsOneWidget
);
});
testWidgets
(
'Push and pop should trigger the observers'
,
(
WidgetTester
tester
)
async
{
final
Map
<
String
,
WidgetBuilder
>
routes
=
<
String
,
WidgetBuilder
>{
'/'
:
(
BuildContext
context
)
=>
OnTapPage
(
id:
'/'
,
onTap:
()
{
Navigator
.
pushNamed
(
context
,
'/A'
);
}),
...
...
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