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
57d1d7be
Unverified
Commit
57d1d7be
authored
Nov 23, 2021
by
Ivan
Committed by
GitHub
Nov 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle new route if moved from one navigator to another (#89226)
parent
52a38840
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
5 deletions
+83
-5
will_pop_scope.dart
packages/flutter/lib/src/widgets/will_pop_scope.dart
+0
-1
will_pop_test.dart
packages/flutter/test/material/will_pop_test.dart
+83
-4
No files found.
packages/flutter/lib/src/widgets/will_pop_scope.dart
View file @
57d1d7be
...
...
@@ -85,7 +85,6 @@ class _WillPopScopeState extends State<WillPopScope> {
@override
void
didUpdateWidget
(
WillPopScope
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
assert
(
_route
==
ModalRoute
.
of
(
context
));
if
(
widget
.
onWillPop
!=
oldWidget
.
onWillPop
&&
_route
!=
null
)
{
if
(
oldWidget
.
onWillPop
!=
null
)
_route
!.
removeScopedWillPopCallback
(
oldWidget
.
onWillPop
!);
...
...
packages/flutter/test/material/will_pop_test.dart
View file @
57d1d7be
...
...
@@ -65,13 +65,35 @@ class SampleForm extends StatelessWidget {
}
// Expose the protected hasScopedWillPopCallback getter
class
TestPageRoute
<
T
>
extends
MaterialPageRoute
<
T
>
{
TestPageRoute
({
required
WidgetBuilder
builder
})
:
super
(
builder:
builder
,
maintainState:
true
);
class
_TestPageRoute
<
T
>
extends
MaterialPageRoute
<
T
>
{
_TestPageRoute
({
RouteSettings
?
settings
,
required
WidgetBuilder
builder
,
})
:
super
(
builder:
builder
,
maintainState:
true
,
settings:
settings
);
bool
get
hasCallback
=>
super
.
hasScopedWillPopCallback
;
}
class
_TestPage
extends
Page
<
dynamic
>
{
_TestPage
({
required
this
.
builder
,
required
LocalKey
key
,
})
:
_key
=
GlobalKey
(),
super
(
key:
key
);
final
WidgetBuilder
builder
;
final
GlobalKey
<
dynamic
>
_key
;
@override
Route
<
dynamic
>
createRoute
(
BuildContext
context
)
{
return
_TestPageRoute
<
dynamic
>(
settings:
this
,
builder:
(
BuildContext
context
)
{
// keep state during move to another location in tree
return
KeyedSubtree
(
key:
_key
,
child:
builder
.
call
(
context
));
});
}
}
void
main
(
)
{
testWidgets
(
'ModalRoute scopedWillPopupCallback can inhibit back button'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -318,7 +340,7 @@ void main() {
late
StateSetter
contentsSetState
;
// call this to rebuild the route's SampleForm contents
bool
contentsEmpty
=
false
;
// when true, don't include the SampleForm in the route
final
TestPageRoute
<
void
>
route
=
TestPageRoute
<
void
>(
final
_TestPageRoute
<
void
>
route
=
_
TestPageRoute
<
void
>(
builder:
(
BuildContext
context
)
{
return
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
...
...
@@ -373,4 +395,61 @@ void main() {
expect
(
route
.
hasCallback
,
isFalse
);
});
testWidgets
(
'should handle new route if page moved from one navigator to another'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/89133
late
StateSetter
contentsSetState
;
bool
moveToAnotherNavigator
=
false
;
final
List
<
Page
<
dynamic
>>
pages
=
<
Page
<
dynamic
>>[
_TestPage
(
key:
UniqueKey
(),
builder:
(
BuildContext
context
)
{
return
WillPopScope
(
onWillPop:
()
async
=>
true
,
child:
const
Text
(
'anchor'
),
);
},
)
];
Widget
_buildNavigator
(
Key
?
key
,
List
<
Page
<
dynamic
>>
pages
)
{
return
Navigator
(
key:
key
,
pages:
pages
,
onPopPage:
(
Route
<
dynamic
>
route
,
dynamic
result
)
{
return
route
.
didPop
(
result
);
},
);
}
Widget
buildFrame
()
{
return
MaterialApp
(
home:
Scaffold
(
body:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
contentsSetState
=
setState
;
if
(
moveToAnotherNavigator
)
{
return
_buildNavigator
(
const
ValueKey
<
int
>(
1
),
pages
);
}
return
_buildNavigator
(
const
ValueKey
<
int
>(
2
),
pages
);
},
),
),
);
}
await
tester
.
pumpWidget
(
buildFrame
());
await
tester
.
pump
();
final
_TestPageRoute
<
dynamic
>
route1
=
ModalRoute
.
of
(
tester
.
element
(
find
.
text
(
'anchor'
)))!
as
_TestPageRoute
<
dynamic
>;
expect
(
route1
.
hasCallback
,
isTrue
);
moveToAnotherNavigator
=
true
;
contentsSetState
(()
{});
await
tester
.
pump
();
final
_TestPageRoute
<
dynamic
>
route2
=
ModalRoute
.
of
(
tester
.
element
(
find
.
text
(
'anchor'
)))!
as
_TestPageRoute
<
dynamic
>;
expect
(
route1
.
hasCallback
,
isFalse
);
expect
(
route2
.
hasCallback
,
isTrue
);
});
}
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