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
cf7a3b04
Commit
cf7a3b04
authored
Dec 03, 2015
by
Hixie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Navigator.canPop(context)
parent
93b1f100
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
0 deletions
+27
-0
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+18
-0
routes.dart
packages/flutter/lib/src/widgets/routes.dart
+3
-0
page_transitions_test.dart
packages/unit/test/widget/page_transitions_test.dart
+6
-0
No files found.
packages/flutter/lib/src/widgets/navigator.dart
View file @
cf7a3b04
...
...
@@ -37,6 +37,9 @@ abstract class Route<T> {
/// responsibility of the Route to later call dispose().
bool
didPop
(
T
result
)
=>
true
;
/// Whether calling didPop() would return false.
bool
get
willHandlePopInternally
=>
false
;
/// The given route has been pushed onto the navigator after this route.
void
didPushNext
(
Route
nextRoute
)
{
}
...
...
@@ -129,6 +132,11 @@ class Navigator extends StatefulComponent {
return
returnValue
;
}
static
bool
canPop
(
BuildContext
context
)
{
NavigatorState
navigator
=
context
.
ancestorStateOfType
(
NavigatorState
);
return
navigator
.
canPop
();
}
static
void
popAndPushNamed
(
BuildContext
context
,
String
routeName
,
{
Set
<
Key
>
mostValuableKeys
})
{
openTransaction
(
context
,
(
NavigatorTransaction
transaction
)
{
transaction
.
pop
();
...
...
@@ -280,7 +288,10 @@ class NavigatorState extends State<Navigator> {
assert
(()
{
_debugLocked
=
true
;
return
true
;
});
Route
route
=
_history
.
last
;
assert
(
route
.
_navigator
==
this
);
bool
debugPredictedWouldPop
;
assert
(()
{
debugPredictedWouldPop
=
!
route
.
willHandlePopInternally
;
return
true
;
});
if
(
route
.
didPop
(
result
))
{
assert
(
debugPredictedWouldPop
);
if
(
_history
.
length
>
1
)
{
setState
(()
{
// We use setState to guarantee that we'll rebuild, since the routes
...
...
@@ -295,6 +306,8 @@ class NavigatorState extends State<Navigator> {
assert
(()
{
_debugLocked
=
false
;
return
true
;
});
return
false
;
}
}
else
{
assert
(!
debugPredictedWouldPop
);
}
assert
(()
{
_debugLocked
=
false
;
return
true
;
});
return
true
;
...
...
@@ -306,6 +319,11 @@ class NavigatorState extends State<Navigator> {
_pop
();
}
bool
canPop
()
{
assert
(
_history
.
length
>
0
);
return
_history
.
length
>
1
||
_history
[
0
].
willHandlePopInternally
;
}
bool
_hadTransaction
=
true
;
bool
openTransaction
(
NavigatorTransactionCallback
callback
)
{
...
...
packages/flutter/lib/src/widgets/routes.dart
View file @
cf7a3b04
...
...
@@ -236,6 +236,9 @@ abstract class LocalHistoryRoute<T> extends Route<T> {
}
return
super
.
didPop
(
result
);
}
bool
get
willHandlePopInternally
{
return
_localHistory
!=
null
&&
_localHistory
.
length
>
0
;
}
}
class
_ModalScopeStatus
extends
InheritedWidget
{
...
...
packages/unit/test/widget/page_transitions_test.dart
View file @
cf7a3b04
...
...
@@ -29,7 +29,9 @@ void main() {
expect
(
tester
.
findText
(
'Settings'
),
isNull
);
expect
(
tester
.
findText
(
'Overlay'
),
isNull
);
expect
(
Navigator
.
canPop
(
containerKey1
.
currentContext
),
isFalse
);
Navigator
.
pushNamed
(
containerKey1
.
currentContext
,
'/settings'
);
expect
(
Navigator
.
canPop
(
containerKey1
.
currentContext
),
isTrue
);
tester
.
pump
();
...
...
@@ -63,6 +65,7 @@ void main() {
expect
(
tester
.
findText
(
'Settings'
),
isOnStage
);
expect
(
tester
.
findText
(
'Overlay'
),
isOnStage
);
expect
(
Navigator
.
canPop
(
containerKey2
.
currentContext
),
isTrue
);
Navigator
.
pop
(
containerKey2
.
currentContext
);
tester
.
pump
();
...
...
@@ -76,6 +79,7 @@ void main() {
expect
(
tester
.
findText
(
'Settings'
),
isOnStage
);
expect
(
tester
.
findText
(
'Overlay'
),
isNull
);
expect
(
Navigator
.
canPop
(
containerKey2
.
currentContext
),
isTrue
);
Navigator
.
pop
(
containerKey2
.
currentContext
);
tester
.
pump
();
...
...
@@ -89,6 +93,8 @@ void main() {
expect
(
tester
.
findText
(
'Settings'
),
isNull
);
expect
(
tester
.
findText
(
'Overlay'
),
isNull
);
expect
(
Navigator
.
canPop
(
containerKey1
.
currentContext
),
isFalse
);
});
});
}
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