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
7e2f555d
Unverified
Commit
7e2f555d
authored
May 28, 2020
by
chunhtai
Committed by
GitHub
May 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix route annoucement for first route and last route (#57339)
parent
e05a67f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
3 deletions
+106
-3
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+11
-3
navigator_test.dart
packages/flutter/test/widgets/navigator_test.dart
+95
-0
No files found.
packages/flutter/lib/src/widgets/navigator.dart
View file @
7e2f555d
...
...
@@ -2293,6 +2293,12 @@ enum _RouteLifecycle {
typedef
_RouteEntryPredicate
=
bool
Function
(
_RouteEntry
entry
);
class
_NotAnnounced
extends
Route
<
void
>
{
// A placeholder for the lastAnnouncedPreviousRoute, the
// lastAnnouncedPoppedNextRoute, and the lastAnnouncedNextRoute before any
// change has been announced.
}
class
_RouteEntry
extends
RouteTransitionRecord
{
_RouteEntry
(
this
.
route
,
{
...
...
@@ -2311,10 +2317,12 @@ class _RouteEntry extends RouteTransitionRecord {
@override
final
Route
<
dynamic
>
route
;
static
Route
<
dynamic
>
notAnnounced
=
_NotAnnounced
();
_RouteLifecycle
currentState
;
Route
<
dynamic
>
lastAnnouncedPreviousRoute
;
// last argument to Route.didChangePrevious
Route
<
dynamic
>
lastAnnouncedPoppedNextRoute
;
// last argument to Route.didPopNext
Route
<
dynamic
>
lastAnnouncedNextRoute
;
// last argument to Route.didChangeNext
Route
<
dynamic
>
lastAnnouncedPreviousRoute
=
notAnnounced
;
// last argument to Route.didChangePrevious
Route
<
dynamic
>
lastAnnouncedPoppedNextRoute
=
notAnnounced
;
// last argument to Route.didPopNext
Route
<
dynamic
>
lastAnnouncedNextRoute
=
notAnnounced
;
// last argument to Route.didChangeNext
bool
get
hasPage
=>
route
.
settings
is
Page
;
...
...
packages/flutter/test/widgets/navigator_test.dart
View file @
7e2f555d
...
...
@@ -1840,6 +1840,57 @@ void main() {
expect
(
tickCount
,
4
);
});
testWidgets
(
'Route annouce correctly for first route and last route'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/57133.
Route
<
void
>
previousOfFirst
=
NotAnnounced
();
Route
<
void
>
nextOfFirst
=
NotAnnounced
();
Route
<
void
>
popNextOfFirst
=
NotAnnounced
();
Route
<
void
>
firstRoute
;
Route
<
void
>
previousOfSecond
=
NotAnnounced
();
Route
<
void
>
nextOfSecond
=
NotAnnounced
();
Route
<
void
>
popNextOfSecond
=
NotAnnounced
();
Route
<
void
>
secondRoute
;
final
GlobalKey
<
NavigatorState
>
navigator
=
GlobalKey
<
NavigatorState
>();
await
tester
.
pumpWidget
(
MaterialApp
(
navigatorKey:
navigator
,
initialRoute:
'/second'
,
onGenerateRoute:
(
RouteSettings
settings
)
{
if
(
settings
.
name
==
'/'
)
{
firstRoute
=
RouteAnnouncementSpy
(
onDidChangeNext:
(
Route
<
void
>
next
)
=>
nextOfFirst
=
next
,
onDidChangePrevious:
(
Route
<
void
>
previous
)
=>
previousOfFirst
=
previous
,
onDidPopNext:
(
Route
<
void
>
next
)
=>
popNextOfFirst
=
next
,
settings:
settings
,
);
return
firstRoute
;
}
secondRoute
=
RouteAnnouncementSpy
(
onDidChangeNext:
(
Route
<
void
>
next
)
=>
nextOfSecond
=
next
,
onDidChangePrevious:
(
Route
<
void
>
previous
)
=>
previousOfSecond
=
previous
,
onDidPopNext:
(
Route
<
void
>
next
)
=>
popNextOfSecond
=
next
,
settings:
settings
,
);
return
secondRoute
;
},
),
);
await
tester
.
pumpAndSettle
();
expect
(
previousOfFirst
,
isNull
);
expect
(
nextOfFirst
,
secondRoute
);
expect
(
popNextOfFirst
,
isA
<
NotAnnounced
>());
expect
(
previousOfSecond
,
firstRoute
);
expect
(
nextOfSecond
,
isNull
);
expect
(
popNextOfSecond
,
isA
<
NotAnnounced
>());
navigator
.
currentState
.
pop
();
expect
(
popNextOfFirst
,
secondRoute
);
});
group
(
'Page api'
,
(){
Widget
buildNavigator
(
List
<
Page
<
dynamic
>>
pages
,
...
...
@@ -2561,6 +2612,50 @@ void main() {
});
}
typedef
AnnouncementCallBack
=
void
Function
(
Route
<
dynamic
>);
class
NotAnnounced
extends
Route
<
void
>
{
/* A place holder for not announced route*/
}
class
RouteAnnouncementSpy
extends
Route
<
void
>
{
RouteAnnouncementSpy
({
this
.
onDidChangePrevious
,
this
.
onDidChangeNext
,
this
.
onDidPopNext
,
RouteSettings
settings
,
})
:
super
(
settings:
settings
);
final
AnnouncementCallBack
onDidChangePrevious
;
final
AnnouncementCallBack
onDidChangeNext
;
final
AnnouncementCallBack
onDidPopNext
;
@override
List
<
OverlayEntry
>
get
overlayEntries
=>
<
OverlayEntry
>[
OverlayEntry
(
builder:
(
BuildContext
context
)
=>
const
Placeholder
(),
)
];
@override
void
didChangeNext
(
Route
<
dynamic
>
nextRoute
)
{
super
.
didChangeNext
(
nextRoute
);
if
(
onDidChangeNext
!=
null
)
onDidChangeNext
(
nextRoute
);
}
@override
void
didChangePrevious
(
Route
<
dynamic
>
previousRoute
)
{
super
.
didChangePrevious
(
previousRoute
);
if
(
onDidChangePrevious
!=
null
)
onDidChangePrevious
(
previousRoute
);
}
@override
void
didPopNext
(
Route
<
dynamic
>
nextRoute
)
{
super
.
didPopNext
(
nextRoute
);
if
(
onDidPopNext
!=
null
)
onDidPopNext
(
nextRoute
);
}
}
class
_TickingWidget
extends
StatefulWidget
{
const
_TickingWidget
({
this
.
onTick
});
...
...
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