Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 13.2.2

- Fixes restoreRouteInformation issue when GoRouter.optionURLReflectsImperativeAPIs is true and the last match is ShellRouteMatch

## 13.2.1

- Updates minimum supported SDK version to Flutter 3.16/Dart 3.2.
Expand Down
27 changes: 18 additions & 9 deletions packages/go_router/lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,27 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
if (configuration.isEmpty) {
return null;
}
final String location;
String? location;
if (GoRouter.optionURLReflectsImperativeAPIs &&
configuration.matches.last is ImperativeRouteMatch) {
location = (configuration.matches.last as ImperativeRouteMatch)
.matches
.uri
.toString();
} else {
location = configuration.uri.toString();
(configuration.matches.last is ImperativeRouteMatch ||
configuration.matches.last is ShellRouteMatch)) {
RouteMatchBase route = configuration.matches.last;

while (route is! ImperativeRouteMatch) {
if (route is ShellRouteMatch && route.matches.isNotEmpty) {
route = route.matches.last;
} else {
break;
}
}

if (route case final ImperativeRouteMatch safeRoute) {
location = safeRoute.matches.uri.toString();
}
}

return RouteInformation(
uri: Uri.parse(location),
uri: Uri.parse(location ?? configuration.uri.toString()),
state: _routeMatchListCodec.encode(configuration),
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 13.2.1
version: 13.2.2
repository: https://github.com/flutter/packages/tree/main/packages/go_router
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22

Expand Down
41 changes: 41 additions & 0 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,47 @@ void main() {
log.clear();
});

testWidgets(
'on push shell route with optionURLReflectImperativeAPIs = true',
(WidgetTester tester) async {
GoRouter.optionURLReflectsImperativeAPIs = true;
final List<RouteBase> routes = <RouteBase>[
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) =>
const DummyScreen(),
routes: <RouteBase>[
ShellRoute(
builder:
(BuildContext context, GoRouterState state, Widget child) =>
child,
routes: <RouteBase>[
GoRoute(
path: 'c',
builder: (BuildContext context, GoRouterState state) =>
const DummyScreen(),
)
],
),
],
),
];

final GoRouter router = await createRouter(routes, tester);

log.clear();
router.push('/c?foo=bar');
final RouteMatchListCodec codec =
RouteMatchListCodec(router.configuration);
await tester.pumpAndSettle();
expect(log, <Object>[
isMethodCall('selectMultiEntryHistory', arguments: null),
IsRouteUpdateCall('/c?foo=bar', false,
codec.encode(router.routerDelegate.currentConfiguration)),
]);
GoRouter.optionURLReflectsImperativeAPIs = false;
});

testWidgets('on push with optionURLReflectImperativeAPIs = true',
(WidgetTester tester) async {
GoRouter.optionURLReflectsImperativeAPIs = true;
Expand Down