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
c38feb3b
Unverified
Commit
c38feb3b
authored
Aug 04, 2021
by
chunhtai
Committed by
GitHub
Aug 04, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Router replaces browser history entry if state changes (#83509)
parent
28f311ad
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
255 additions
and
54 deletions
+255
-54
system_navigator.dart
packages/flutter/lib/src/services/system_navigator.dart
+18
-4
router.dart
packages/flutter/lib/src/widgets/router.dart
+66
-38
system_navigator_test.dart
packages/flutter/test/services/system_navigator_test.dart
+6
-2
route_notification_messages_test.dart
...lutter/test/widgets/route_notification_messages_test.dart
+8
-0
router_test.dart
packages/flutter/test/widgets/router_test.dart
+157
-10
No files found.
packages/flutter/lib/src/services/system_navigator.dart
View file @
c38feb3b
...
@@ -67,20 +67,34 @@ class SystemNavigator {
...
@@ -67,20 +67,34 @@ class SystemNavigator {
/// Notifies the platform for a route information change.
/// Notifies the platform for a route information change.
///
///
/// On web,
creates a new browser history entry and update URL with the route
/// On web,
this method behaves differently based on the single-entry or
///
information. Whether the history holds one entry or multiple entries is
///
multiple-entries history mode. Use the [selectSingleEntryHistory] and
///
determined by [selectSingleEntryHistory] and [selectMultiEntryHistory]
.
///
[selectMultiEntryHistory] to toggle between modes
.
///
///
/// Currently, this is ignored on other platforms.
/// For single-entry mode, this method replaces the current URL and state in
/// the current history entry. The flag `replace` is ignored.
///
/// For multiple-entries mode, this method creates a new history entry on top
/// of the current entry if the `replace` is false, thus the user will
/// be on a new history entry as if the user has visited a new page, and the
/// browser back button brings the user back to the previous entry. If
/// `replace` is true, this method only updates the URL and the state in the
/// current history entry without pushing a new one.
///
/// This method is ignored on other platforms.
///
/// The `replace` flag defaults to false.
static
Future
<
void
>
routeInformationUpdated
({
static
Future
<
void
>
routeInformationUpdated
({
required
String
location
,
required
String
location
,
Object
?
state
,
Object
?
state
,
bool
replace
=
false
,
})
{
})
{
return
SystemChannels
.
navigation
.
invokeMethod
<
void
>(
return
SystemChannels
.
navigation
.
invokeMethod
<
void
>(
'routeInformationUpdated'
,
'routeInformationUpdated'
,
<
String
,
dynamic
>{
<
String
,
dynamic
>{
'location'
:
location
,
'location'
:
location
,
'state'
:
state
,
'state'
:
state
,
'replace'
:
replace
,
},
},
);
);
}
}
...
...
packages/flutter/lib/src/widgets/router.dart
View file @
c38feb3b
This diff is collapsed.
Click to expand it.
packages/flutter/test/services/system_navigator_test.dart
View file @
c38feb3b
...
@@ -43,11 +43,15 @@ void main() {
...
@@ -43,11 +43,15 @@ void main() {
]);
]);
await
verify
(()
=>
SystemNavigator
.
routeInformationUpdated
(
location:
'a'
),
<
Object
>[
await
verify
(()
=>
SystemNavigator
.
routeInformationUpdated
(
location:
'a'
),
<
Object
>[
isMethodCall
(
'routeInformationUpdated'
,
arguments:
<
String
,
dynamic
>{
'location'
:
'a'
,
'state'
:
null
}),
isMethodCall
(
'routeInformationUpdated'
,
arguments:
<
String
,
dynamic
>{
'location'
:
'a'
,
'state'
:
null
,
'replace'
:
false
}),
]);
]);
await
verify
(()
=>
SystemNavigator
.
routeInformationUpdated
(
location:
'a'
,
state:
true
),
<
Object
>[
await
verify
(()
=>
SystemNavigator
.
routeInformationUpdated
(
location:
'a'
,
state:
true
),
<
Object
>[
isMethodCall
(
'routeInformationUpdated'
,
arguments:
<
String
,
dynamic
>{
'location'
:
'a'
,
'state'
:
true
}),
isMethodCall
(
'routeInformationUpdated'
,
arguments:
<
String
,
dynamic
>{
'location'
:
'a'
,
'state'
:
true
,
'replace'
:
false
}),
]);
await
verify
(()
=>
SystemNavigator
.
routeInformationUpdated
(
location:
'a'
,
state:
true
,
replace:
true
),
<
Object
>[
isMethodCall
(
'routeInformationUpdated'
,
arguments:
<
String
,
dynamic
>{
'location'
:
'a'
,
'state'
:
true
,
'replace'
:
true
}),
]);
]);
await
verify
(()
=>
SystemNavigator
.
routeUpdated
(
routeName:
'a'
,
previousRouteName:
'b'
),
<
Object
>[
await
verify
(()
=>
SystemNavigator
.
routeUpdated
(
routeName:
'a'
,
previousRouteName:
'b'
),
<
Object
>[
...
...
packages/flutter/test/widgets/route_notification_messages_test.dart
View file @
c38feb3b
...
@@ -69,6 +69,7 @@ void main() {
...
@@ -69,6 +69,7 @@ void main() {
arguments:
<
String
,
dynamic
>{
arguments:
<
String
,
dynamic
>{
'location'
:
'/'
,
'location'
:
'/'
,
'state'
:
null
,
'state'
:
null
,
'replace'
:
false
,
},
},
),
),
]);
]);
...
@@ -86,6 +87,7 @@ void main() {
...
@@ -86,6 +87,7 @@ void main() {
arguments:
<
String
,
dynamic
>{
arguments:
<
String
,
dynamic
>{
'location'
:
'/A'
,
'location'
:
'/A'
,
'state'
:
null
,
'state'
:
null
,
'replace'
:
false
,
},
},
),
),
);
);
...
@@ -103,6 +105,7 @@ void main() {
...
@@ -103,6 +105,7 @@ void main() {
arguments:
<
String
,
dynamic
>{
arguments:
<
String
,
dynamic
>{
'location'
:
'/'
,
'location'
:
'/'
,
'state'
:
null
,
'state'
:
null
,
'replace'
:
false
,
},
},
),
),
);
);
...
@@ -174,6 +177,7 @@ void main() {
...
@@ -174,6 +177,7 @@ void main() {
arguments:
<
String
,
dynamic
>{
arguments:
<
String
,
dynamic
>{
'location'
:
'/'
,
'location'
:
'/'
,
'state'
:
null
,
'state'
:
null
,
'replace'
:
false
,
},
},
),
),
]);
]);
...
@@ -191,6 +195,7 @@ void main() {
...
@@ -191,6 +195,7 @@ void main() {
arguments:
<
String
,
dynamic
>{
arguments:
<
String
,
dynamic
>{
'location'
:
'/A'
,
'location'
:
'/A'
,
'state'
:
null
,
'state'
:
null
,
'replace'
:
false
,
},
},
),
),
);
);
...
@@ -208,6 +213,7 @@ void main() {
...
@@ -208,6 +213,7 @@ void main() {
arguments:
<
String
,
dynamic
>{
arguments:
<
String
,
dynamic
>{
'location'
:
'/B'
,
'location'
:
'/B'
,
'state'
:
null
,
'state'
:
null
,
'replace'
:
false
,
},
},
),
),
);
);
...
@@ -243,6 +249,7 @@ void main() {
...
@@ -243,6 +249,7 @@ void main() {
arguments:
<
String
,
dynamic
>{
arguments:
<
String
,
dynamic
>{
'location'
:
'/home'
,
'location'
:
'/home'
,
'state'
:
null
,
'state'
:
null
,
'replace'
:
false
,
},
},
),
),
]);
]);
...
@@ -294,6 +301,7 @@ void main() {
...
@@ -294,6 +301,7 @@ void main() {
isMethodCall
(
'routeInformationUpdated'
,
arguments:
<
String
,
dynamic
>{
isMethodCall
(
'routeInformationUpdated'
,
arguments:
<
String
,
dynamic
>{
'location'
:
'update'
,
'location'
:
'update'
,
'state'
:
'state'
,
'state'
:
'state'
,
'replace'
:
false
,
}),
}),
]);
]);
});
});
...
...
packages/flutter/test/widgets/router_test.dart
View file @
c38feb3b
This diff is collapsed.
Click to expand it.
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