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
57e81894
Commit
57e81894
authored
Jan 24, 2020
by
Greg Spencer
Committed by
Flutter GitHub Bot
Jan 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Guard against a null navigator on popping a route. (#49329)
parent
3f973157
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
1 deletion
+49
-1
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+1
-1
navigator_test.dart
packages/flutter/test/widgets/navigator_test.dart
+48
-0
No files found.
packages/flutter/lib/src/widgets/navigator.dart
View file @
57e81894
...
...
@@ -136,7 +136,7 @@ abstract class Route<T> {
@mustCallSuper
TickerFuture
didPush
()
{
return
TickerFuture
.
complete
()..
then
<
void
>((
void
_
)
{
navigator
.
focusScopeNode
.
requestFocus
();
navigator
?.
focusScopeNode
?
.
requestFocus
();
});
}
...
...
packages/flutter/test/widgets/navigator_test.dart
View file @
57e81894
...
...
@@ -1036,6 +1036,54 @@ void main() {
expect
(
find
.
byKey
(
keyAB
),
findsNothing
);
});
testWidgets
(
"Popping immediately after pushing doesn't crash"
,
(
WidgetTester
tester
)
async
{
// Added this test to protect against regression of https://github.com/flutter/flutter/issues/45539
final
Map
<
String
,
WidgetBuilder
>
routes
=
<
String
,
WidgetBuilder
>{
'/'
:
(
BuildContext
context
)
=>
OnTapPage
(
id:
'/'
,
onTap:
()
{
Navigator
.
pushNamed
(
context
,
'/A'
);
Navigator
.
of
(
context
).
pop
();
}),
'/A'
:
(
BuildContext
context
)
=>
OnTapPage
(
id:
'A'
,
onTap:
()
{
Navigator
.
pop
(
context
);
}),
};
bool
isPushed
=
false
;
bool
isPopped
=
false
;
final
TestObserver
observer
=
TestObserver
()
..
onPushed
=
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
// Pushes the initial route.
expect
(
route
is
PageRoute
&&
route
.
settings
.
name
==
'/'
,
isTrue
);
expect
(
previousRoute
,
isNull
);
isPushed
=
true
;
}
..
onPopped
=
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
isPopped
=
true
;
};
await
tester
.
pumpWidget
(
MaterialApp
(
routes:
routes
,
navigatorObservers:
<
NavigatorObserver
>[
observer
],
));
expect
(
find
.
text
(
'/'
),
findsOneWidget
);
expect
(
find
.
text
(
'A'
),
findsNothing
);
expect
(
isPushed
,
isTrue
);
expect
(
isPopped
,
isFalse
);
isPushed
=
false
;
isPopped
=
false
;
observer
.
onPushed
=
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
expect
(
route
is
PageRoute
&&
route
.
settings
.
name
==
'/A'
,
isTrue
);
expect
(
previousRoute
is
PageRoute
&&
previousRoute
.
settings
.
name
==
'/'
,
isTrue
);
isPushed
=
true
;
};
await
tester
.
tap
(
find
.
text
(
'/'
));
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
find
.
text
(
'/'
),
findsOneWidget
);
expect
(
find
.
text
(
'A'
),
findsNothing
);
expect
(
isPushed
,
isTrue
);
expect
(
isPopped
,
isTrue
);
});
group
(
'error control test'
,
()
{
testWidgets
(
'onUnknownRoute null and onGenerateRoute returns null'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
NavigatorState
>
navigatorKey
=
GlobalKey
<
NavigatorState
>();
...
...
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