Skip to content

Commit 2a7df7a

Browse files
authored
[go_router] fix Popping state and re-rendering scaffold at the same time doesn't update the URL on web [new] (#8352)
> the old pr #6953 Change the 3 files of lib and add a example, because issue flutter/flutter#150312 The reason for the issue is when call `counterStream.increment();` will notify `notifyListeners()` of `StreamListener`, and finally affect `_handleRouteInformationProviderNotification` of` _RouterState` in `packages/flutter/lib/src/widgets/router.dart`. When pop should not call `_handleRouteInformationProviderNotification` otherwise will be path wrong. because the value of `GoRouteInformationProvider` is not the latest. ## Solution: always make the value of `GoRouteInformationProvider` knew the latest `RouteInformation`[but not to do `notifyListeners()`]. i don't know if adding `pop` to `NavigatingType` is reasonable, if any place needs to be changed please tell me. ## Result: After changed, the issue been solved and all the others pop not be affect such as drawer/dialog/bottomsheet, See the video below. > flutter/flutter#150312 > exempt from version changes > this PR is exempt from CHANGELOG changes. > this PR is test-exempt. > the `go_route_test.dart` will error if `testWidgets('throw if redirect to itself')`[I have this problem when I pull the online branch. it's not relate this PR, All of the others test success, So I view this as all test cases successfully passing.] ``` Exception has occurred. _AssertionError ('package:go_router/src/parser.dart': Failed assertion: line 110 pos 18: '!matchList.last.route.redirectOnly': A redirect-only route must redirect to location different from itself. The offending route: GoRoute#0ae4e(name: null, path: "route", Redirect Only)) ```
1 parent 93e91f3 commit 2a7df7a

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

packages/go_router/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
## 15.2.1
2+
3+
* Fixes Popping state and re-rendering scaffold at the same time doesn't update the URL on web.
4+
15
## 15.2.0
26

3-
- `GoRouteData` now defines `.location`, `.go(context)`, `.push(context)`, `.pushReplacement(context)`, and `replace(context)` to be used for [Type-safe routing](https://pub.dev/documentation/go_router/latest/topics/Type-safe%20routes-topic.html). **Requires go_router_builder >= 3.0.0**.
7+
* `GoRouteData` now defines `.location`, `.go(context)`, `.push(context)`, `.pushReplacement(context)`, and `replace(context)` to be used for [Type-safe routing](https://pub.dev/documentation/go_router/latest/topics/Type-safe%20routes-topic.html). **Requires go_router_builder >= 3.0.0**.
48

59
## 15.1.3
610

packages/go_router/lib/src/router.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,16 @@ class GoRouter implements RouterConfig<RouteMatchList> {
496496
///
497497
/// If the top-most route is a pop up or dialog, this method pops it instead
498498
/// of any GoRoute under it.
499+
///
500+
/// Ensure that the `value` of `routeInformationProvider` is synced
501+
/// with `routerDelegate.currentConfiguration`.
499502
void pop<T extends Object?>([T? result]) {
500503
assert(() {
501504
log('popping ${routerDelegate.currentConfiguration.uri}');
502505
return true;
503506
}());
504507
routerDelegate.pop<T>(result);
508+
restore(routerDelegate.currentConfiguration);
505509
}
506510

507511
/// Refresh the route.

packages/go_router/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: go_router
22
description: A declarative router for Flutter based on Navigation 2 supporting
33
deep linking, data-driven routes and more
4-
version: 15.2.0
4+
version: 15.2.1
55
repository: https://github.com/flutter/packages/tree/main/packages/go_router
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
77

packages/go_router/test/delegate_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ Future<GoRouter> createGoRouterWithStatefulShellRoute(
7878

7979
void main() {
8080
group('pop', () {
81+
testWidgets('restore() update currentConfiguration in pop()',
82+
(WidgetTester tester) async {
83+
final ValueNotifier<int> valueNotifier = ValueNotifier<int>(0);
84+
final GoRouter goRouter = await createGoRouter(tester,
85+
refreshListenable: valueNotifier, dispose: false);
86+
87+
goRouter.push('/a');
88+
await tester.pumpAndSettle();
89+
90+
goRouter.pop();
91+
valueNotifier.notifyListeners();
92+
await tester.pumpAndSettle();
93+
expect(
94+
goRouter
95+
.routerDelegate.currentConfiguration.matches.last.matchedLocation,
96+
'/',
97+
);
98+
99+
addTearDown(valueNotifier.dispose);
100+
addTearDown(goRouter.dispose);
101+
});
102+
81103
testWidgets('removes the last element', (WidgetTester tester) async {
82104
final GoRouter goRouter = await createGoRouter(tester)
83105
..push('/error');

0 commit comments

Comments
 (0)