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
7168421e
Unverified
Commit
7168421e
authored
Feb 12, 2020
by
chunhtai
Committed by
GitHub
Feb 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes route name annoucement in navigator (#50495)
parent
7820641a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
41 deletions
+25
-41
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+10
-20
route_notification_messages.dart
.../flutter/lib/src/widgets/route_notification_messages.dart
+5
-11
route_notification_messages_test.dart
...lutter/test/widgets/route_notification_messages_test.dart
+10
-10
No files found.
packages/flutter/lib/src/widgets/navigator.dart
View file @
7168421e
...
...
@@ -77,18 +77,6 @@ enum RoutePopDisposition {
bubble
,
}
/// Name for the method which is used for sending messages from framework to
/// engine after a route is popped.
const
String
_routePoppedMethod
=
'routePopped'
;
/// Name for the method which is used for sending messages from framework to
/// engine after a route is pushed.
const
String
_routePushedMethod
=
'routePushed'
;
/// Name for the method which is used for sending messages from framework to
/// engine after a route is replaced.
const
String
_routeReplacedMethod
=
'routeReplaced'
;
/// An abstraction for an entry managed by a [Navigator].
///
/// This class defines an abstract interface between the navigator and the
...
...
@@ -1793,7 +1781,6 @@ class _RouteEntry {
if
(
isNewFirst
)
{
route
.
didChangeNext
(
null
);
}
RouteNotificationMessages
.
maybeNotifyRouteChange
(
_routePushedMethod
,
route
,
previous
);
for
(
final
NavigatorObserver
observer
in
navigator
.
widget
.
observers
)
observer
.
didPush
(
route
,
previousPresent
);
}
...
...
@@ -1829,12 +1816,10 @@ class _RouteEntry {
}
if
(
previousState
==
_RouteLifecycle
.
replace
||
previousState
==
_RouteLifecycle
.
pushReplace
)
{
RouteNotificationMessages
.
maybeNotifyRouteChange
(
_routeReplacedMethod
,
route
,
previous
);
for
(
final
NavigatorObserver
observer
in
navigator
.
widget
.
observers
)
observer
.
didReplace
(
newRoute:
route
,
oldRoute:
previous
);
}
else
{
assert
(
previousState
==
_RouteLifecycle
.
push
);
RouteNotificationMessages
.
maybeNotifyRouteChange
(
_routePushedMethod
,
route
,
previous
);
for
(
final
NavigatorObserver
observer
in
navigator
.
widget
.
observers
)
observer
.
didPush
(
route
,
previousPresent
);
}
...
...
@@ -1852,11 +1837,6 @@ class _RouteEntry {
currentState
=
_RouteLifecycle
.
popping
;
for
(
final
NavigatorObserver
observer
in
navigator
.
widget
.
observers
)
observer
.
didPop
(
route
,
previousPresent
);
RouteNotificationMessages
.
maybeNotifyRouteChange
(
_routePoppedMethod
,
route
,
previousPresent
,
);
}
void
handleRemoval
({
@required
NavigatorState
navigator
,
@required
Route
<
dynamic
>
previousPresent
})
{
...
...
@@ -2009,6 +1989,8 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
yield
*
entry
.
route
.
overlayEntries
;
}
String
_lastAnnouncedRouteName
;
void
_flushHistoryUpdates
({
bool
rearrangeOverlay
=
true
})
{
assert
(
_debugLocked
);
// Clean up the list, sending updates to the routes that changed. Notably,
...
...
@@ -2117,6 +2099,14 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
// notifications.
_flushRouteAnnouncement
();
// Announces route name changes.
final
_RouteEntry
lastEntry
=
_history
.
lastWhere
(
_RouteEntry
.
isPresentPredicate
,
orElse:
()
=>
null
);
final
String
routeName
=
lastEntry
?.
route
?.
settings
?.
name
;
if
(
routeName
!=
_lastAnnouncedRouteName
)
{
RouteNotificationMessages
.
maybeNotifyRouteChange
(
routeName
,
_lastAnnouncedRouteName
);
_lastAnnouncedRouteName
=
routeName
;
}
// Lastly, removes the overlay entries of all marked entries and disposes
// them.
for
(
final
_RouteEntry
entry
in
toBeDisposed
)
{
...
...
packages/flutter/lib/src/widgets/route_notification_messages.dart
View file @
7168421e
...
...
@@ -5,19 +5,17 @@
import
'package:flutter/foundation.dart'
;
import
'package:flutter/services.dart'
;
import
'navigator.dart'
;
/// Messages for route change notifications.
class
RouteNotificationMessages
{
// This class is not meant to be instatiated or extended; this constructor
// This class is not meant to be insta
n
tiated or extended; this constructor
// prevents instantiation and extension.
// ignore: unused_element
RouteNotificationMessages
.
_
();
/// When the engine is Web notify the platform for a route change.
static
void
maybeNotifyRouteChange
(
String
methodName
,
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRout
e
)
{
static
void
maybeNotifyRouteChange
(
String
routeName
,
String
previousRouteNam
e
)
{
if
(
kIsWeb
)
{
_notifyRouteChange
(
methodName
,
route
,
previousRout
e
);
_notifyRouteChange
(
routeName
,
previousRouteNam
e
);
}
else
{
// No op.
}
...
...
@@ -25,17 +23,13 @@ class RouteNotificationMessages {
/// Notifies the platform of a route change.
///
/// There are three methods: 'routePushed', 'routePopped', 'routeReplaced'.
///
/// See also:
///
/// * [SystemChannels.navigation], which handles subsequent navigation
/// requests.
static
void
_notifyRouteChange
(
String
methodName
,
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
final
String
previousRouteName
=
previousRoute
?.
settings
?.
name
;
final
String
routeName
=
route
?.
settings
?.
name
;
static
void
_notifyRouteChange
(
String
routeName
,
String
previousRouteName
)
{
SystemChannels
.
navigation
.
invokeMethod
<
void
>(
methodName
,
'routeUpdated'
,
<
String
,
dynamic
>{
'previousRouteName'
:
previousRouteName
,
'routeName'
:
routeName
,
...
...
packages/flutter/test/widgets/route_notification_messages_test.dart
View file @
7168421e
...
...
@@ -63,7 +63,7 @@ void main() {
expect
(
log
.
last
,
isMethodCall
(
'route
Push
ed'
,
'route
Updat
ed'
,
arguments:
<
String
,
dynamic
>{
'previousRouteName'
:
null
,
'routeName'
:
'/'
,
...
...
@@ -78,7 +78,7 @@ void main() {
expect
(
log
.
last
,
isMethodCall
(
'route
Push
ed'
,
'route
Updat
ed'
,
arguments:
<
String
,
dynamic
>{
'previousRouteName'
:
'/'
,
'routeName'
:
'/A'
,
...
...
@@ -93,10 +93,10 @@ void main() {
expect
(
log
.
last
,
isMethodCall
(
'route
Popp
ed'
,
'route
Updat
ed'
,
arguments:
<
String
,
dynamic
>{
'previousRouteName'
:
'/'
,
'routeName'
:
'/
A
'
,
'previousRouteName'
:
'/
A
'
,
'routeName'
:
'/'
,
},
));
});
...
...
@@ -130,7 +130,7 @@ void main() {
expect
(
log
.
last
,
isMethodCall
(
'route
Push
ed'
,
'route
Updat
ed'
,
arguments:
<
String
,
dynamic
>{
'previousRouteName'
:
null
,
'routeName'
:
'/'
,
...
...
@@ -145,7 +145,7 @@ void main() {
expect
(
log
.
last
,
isMethodCall
(
'route
Push
ed'
,
'route
Updat
ed'
,
arguments:
<
String
,
dynamic
>{
'previousRouteName'
:
'/'
,
'routeName'
:
'/A'
,
...
...
@@ -160,7 +160,7 @@ void main() {
expect
(
log
.
last
,
isMethodCall
(
'route
Replac
ed'
,
'route
Updat
ed'
,
arguments:
<
String
,
dynamic
>{
'previousRouteName'
:
'/A'
,
'routeName'
:
'/B'
,
...
...
@@ -195,7 +195,7 @@ void main() {
expect
(
log
,
hasLength
(
1
));
expect
(
log
.
last
,
isMethodCall
(
'route
Push
ed'
,
arguments:
<
String
,
dynamic
>{
isMethodCall
(
'route
Updat
ed'
,
arguments:
<
String
,
dynamic
>{
'previousRouteName'
:
null
,
'routeName'
:
'/home'
,
}),
...
...
@@ -208,7 +208,7 @@ void main() {
expect
(
log
,
hasLength
(
2
));
expect
(
log
.
last
,
isMethodCall
(
'route
Push
ed'
,
arguments:
<
String
,
dynamic
>{
isMethodCall
(
'route
Updat
ed'
,
arguments:
<
String
,
dynamic
>{
'previousRouteName'
:
'/home'
,
'routeName'
:
null
,
}),
...
...
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