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
ff235862
Unverified
Commit
ff235862
authored
Apr 13, 2020
by
Darren Austin
Committed by
GitHub
Apr 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow WIllPopCallback to return null or false to veto the pop. (#54640)
parent
d1e05281
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
4 deletions
+51
-4
routes.dart
packages/flutter/lib/src/widgets/routes.dart
+6
-4
will_pop_test.dart
packages/flutter/test/material/will_pop_test.dart
+45
-0
No files found.
packages/flutter/lib/src/widgets/routes.dart
View file @
ff235862
...
...
@@ -1239,9 +1239,11 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
final
List
<
WillPopCallback
>
_willPopCallbacks
=
<
WillPopCallback
>[];
/// Returns the value of the first callback added with
/// [addScopedWillPopCallback] that returns false. If they all return true,
/// returns the inherited method's result (see [Route.willPop]).
/// Returns [RoutePopDisposition.doNotPop] if any of callbacks added with
/// [addScopedWillPopCallback] returns either false or null. If they all
/// return true, the base [Route.willPop]'s result will be returned. The
/// callbacks will be called in the order they were added, and will only be
/// called if all previous callbacks returned true.
///
/// Typically this method is not overridden because applications usually
/// don't create modal routes directly, they use higher level primitives
...
...
@@ -1260,7 +1262,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
final
_ModalScopeState
<
T
>
scope
=
_scopeKey
.
currentState
;
assert
(
scope
!=
null
);
for
(
final
WillPopCallback
callback
in
List
<
WillPopCallback
>.
from
(
_willPopCallbacks
))
{
if
(
!
await
callback
()
)
if
(
await
callback
()
!=
true
)
return
RoutePopDisposition
.
doNotPop
;
}
return
await
super
.
willPop
();
...
...
packages/flutter/test/material/will_pop_test.dart
View file @
ff235862
...
...
@@ -128,6 +128,51 @@ void main() {
expect
(
find
.
text
(
'Sample Page'
),
findsNothing
);
});
testWidgets
(
'willPop will only pop if the callback returns true'
,
(
WidgetTester
tester
)
async
{
Widget
buildFrame
()
{
return
MaterialApp
(
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Home'
)),
body:
Builder
(
builder:
(
BuildContext
context
)
{
return
Center
(
child:
FlatButton
(
child:
const
Text
(
'X'
),
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
<
void
>(
builder:
(
BuildContext
context
)
{
return
SampleForm
(
callback:
()
=>
Future
<
bool
>.
value
(
willPopValue
),
);
},
));
},
),
);
},
),
),
);
}
await
tester
.
pumpWidget
(
buildFrame
());
await
tester
.
tap
(
find
.
text
(
'X'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Sample Form'
),
findsOneWidget
);
// Should not pop if callback returns null
willPopValue
=
null
;
await
tester
.
tap
(
find
.
byTooltip
(
'Back'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Sample Form'
),
findsOneWidget
);
// Should pop if callback returns true
willPopValue
=
true
;
await
tester
.
tap
(
find
.
byTooltip
(
'Back'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Sample Form'
),
findsNothing
);
});
testWidgets
(
'Form.willPop can inhibit back button'
,
(
WidgetTester
tester
)
async
{
Widget
buildFrame
()
{
return
MaterialApp
(
...
...
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