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
00b1903b
Unverified
Commit
00b1903b
authored
Jul 09, 2020
by
chunhtai
Committed by
GitHub
Jul 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a flag to toggle navigator route update reporting (#60621)
parent
5a00d54e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
5 deletions
+70
-5
app.dart
packages/flutter/lib/src/widgets/app.dart
+1
-0
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+27
-5
route_notification_messages_test.dart
...lutter/test/widgets/route_notification_messages_test.dart
+42
-0
No files found.
packages/flutter/lib/src/widgets/app.dart
View file @
00b1903b
...
@@ -1308,6 +1308,7 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
...
@@ -1308,6 +1308,7 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
},
},
onUnknownRoute:
_onUnknownRoute
,
onUnknownRoute:
_onUnknownRoute
,
observers:
widget
.
navigatorObservers
,
observers:
widget
.
navigatorObservers
,
reportsRouteUpdateToEngine:
true
,
);
);
}
}
...
...
packages/flutter/lib/src/widgets/navigator.dart
View file @
00b1903b
...
@@ -1397,11 +1397,13 @@ class Navigator extends StatefulWidget {
...
@@ -1397,11 +1397,13 @@ class Navigator extends StatefulWidget {
this
.
onGenerateRoute
,
this
.
onGenerateRoute
,
this
.
onUnknownRoute
,
this
.
onUnknownRoute
,
this
.
transitionDelegate
=
const
DefaultTransitionDelegate
<
dynamic
>(),
this
.
transitionDelegate
=
const
DefaultTransitionDelegate
<
dynamic
>(),
this
.
reportsRouteUpdateToEngine
=
false
,
this
.
observers
=
const
<
NavigatorObserver
>[],
this
.
observers
=
const
<
NavigatorObserver
>[],
})
:
assert
(
pages
!=
null
),
})
:
assert
(
pages
!=
null
),
assert
(
onGenerateInitialRoutes
!=
null
),
assert
(
onGenerateInitialRoutes
!=
null
),
assert
(
transitionDelegate
!=
null
),
assert
(
transitionDelegate
!=
null
),
assert
(
observers
!=
null
),
assert
(
observers
!=
null
),
assert
(
reportsRouteUpdateToEngine
!=
null
),
super
(
key:
key
);
super
(
key:
key
);
/// The list of pages with which to populate the history.
/// The list of pages with which to populate the history.
...
@@ -1497,6 +1499,22 @@ class Navigator extends StatefulWidget {
...
@@ -1497,6 +1499,22 @@ class Navigator extends StatefulWidget {
/// will be primed.
/// will be primed.
final
RouteListFactory
onGenerateInitialRoutes
;
final
RouteListFactory
onGenerateInitialRoutes
;
/// Whether this navigator should report route update message back to the
/// engine when the top-most route changes.
///
/// If the property is set to true, this navigator automatically sends the
/// route update message to the engine when it detects top-most route changes.
/// The messages are used by the web engine to update the browser URL bar.
///
/// If there are multiple navigators in the widget tree, at most one of them
/// can set this property to true (typically, the top-most one created from
/// the [WidgetsApp]). Otherwise, the web engine may receive multiple route
/// update messages from different navigators and fail to update the URL
/// bar.
///
/// Defaults to false.
final
bool
reportsRouteUpdateToEngine
;
/// Push a named route onto the navigator that most tightly encloses the given
/// Push a named route onto the navigator that most tightly encloses the given
/// context.
/// context.
///
///
...
@@ -3244,11 +3262,15 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
...
@@ -3244,11 +3262,15 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
_flushRouteAnnouncement
();
_flushRouteAnnouncement
();
// Announces route name changes.
// Announces route name changes.
final
_RouteEntry
lastEntry
=
_history
.
lastWhere
(
_RouteEntry
.
isPresentPredicate
,
orElse:
()
=>
null
);
if
(
widget
.
reportsRouteUpdateToEngine
)
{
final
String
routeName
=
lastEntry
?.
route
?.
settings
?.
name
;
final
_RouteEntry
lastEntry
=
_history
.
lastWhere
(
if
(
routeName
!=
_lastAnnouncedRouteName
)
{
_RouteEntry
.
isPresentPredicate
,
orElse:
()
=>
null
);
RouteNotificationMessages
.
maybeNotifyRouteChange
(
routeName
,
_lastAnnouncedRouteName
);
final
String
routeName
=
lastEntry
?.
route
?.
settings
?.
name
;
_lastAnnouncedRouteName
=
routeName
;
if
(
routeName
!=
_lastAnnouncedRouteName
)
{
RouteNotificationMessages
.
maybeNotifyRouteChange
(
routeName
,
_lastAnnouncedRouteName
);
_lastAnnouncedRouteName
=
routeName
;
}
}
}
// Lastly, removes the overlay entries of all marked entries and disposes
// Lastly, removes the overlay entries of all marked entries and disposes
...
...
packages/flutter/test/widgets/route_notification_messages_test.dart
View file @
00b1903b
...
@@ -103,6 +103,48 @@ void main() {
...
@@ -103,6 +103,48 @@ void main() {
));
));
});
});
testWidgets
(
'Navigator does not report route name by default'
,
(
WidgetTester
tester
)
async
{
final
List
<
MethodCall
>
log
=
<
MethodCall
>[];
SystemChannels
.
navigation
.
setMockMethodCallHandler
((
MethodCall
methodCall
)
async
{
log
.
add
(
methodCall
);
});
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Navigator
(
pages:
<
Page
<
void
>>[
TransitionBuilderPage
<
void
>(
name:
'/'
,
pageBuilder:
(
BuildContext
context
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
)
=>
const
Placeholder
(),
),
],
onPopPage:
(
Route
<
void
>
route
,
void
result
)
=>
false
,
)
));
expect
(
log
,
hasLength
(
0
));
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Navigator
(
pages:
<
Page
<
void
>>[
TransitionBuilderPage
<
void
>(
name:
'/'
,
pageBuilder:
(
BuildContext
context
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
)
=>
const
Placeholder
(),
),
TransitionBuilderPage
<
void
>(
name:
'/abc'
,
pageBuilder:
(
BuildContext
context
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
)
=>
const
Placeholder
(),
),
],
onPopPage:
(
Route
<
void
>
route
,
void
result
)
=>
false
,
)
));
await
tester
.
pumpAndSettle
();
expect
(
log
,
hasLength
(
0
));
});
testWidgets
(
'Replace should send platform messages'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Replace should send platform messages'
,
(
WidgetTester
tester
)
async
{
final
Map
<
String
,
WidgetBuilder
>
routes
=
<
String
,
WidgetBuilder
>{
final
Map
<
String
,
WidgetBuilder
>
routes
=
<
String
,
WidgetBuilder
>{
'/'
:
(
BuildContext
context
)
=>
OnTapPage
(
'/'
:
(
BuildContext
context
)
=>
OnTapPage
(
...
...
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