Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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.4

- Updates examples to use uri.path instead of uri.toString() for accessing the current location.

## 13.2.3

- Fixes an issue where deep links without path caused an exception
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/example/lib/shell_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ScaffoldWithNavBar extends StatelessWidget {
}

static int _calculateSelectedIndex(BuildContext context) {
final String location = GoRouterState.of(context).uri.toString();
final String location = GoRouterState.of(context).uri.path;
if (location.startsWith('/a')) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class ScaffoldWithNavBar extends StatelessWidget {
}

static int _calculateSelectedIndex(BuildContext context) {
final String location = GoRouterState.of(context).uri.toString();
final String location = GoRouterState.of(context).uri.path;
if (location.startsWith('/a')) {
return 0;
}
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.3
version: 13.2.4
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
32 changes: 15 additions & 17 deletions packages/go_router/test/go_router_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ void main() {
path: '/',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text('1 ${GoRouterState.of(context).uri}');
return Text('1 ${GoRouterState.of(context).uri.path}');
});
},
routes: <GoRoute>[
GoRoute(
path: 'a',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text('2 ${GoRouterState.of(context).uri}');
return Text('2 ${GoRouterState.of(context).uri.path}');
});
}),
]),
];
final GoRouter router = await createRouter(routes, tester);
router.go('/?p=123');
router.go('/');
await tester.pumpAndSettle();
expect(find.text('1 /?p=123'), findsOneWidget);
expect(find.text('1 /'), findsOneWidget);

router.go('/a');
await tester.pumpAndSettle();
Expand All @@ -74,7 +74,7 @@ void main() {
path: '/',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text('1 ${GoRouterState.of(context).uri}');
return Text('1 ${GoRouterState.of(context).uri.path}');
});
},
routes: <GoRoute>[
Expand Down Expand Up @@ -110,23 +110,22 @@ void main() {
path: '/',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text(GoRouterState.of(context).uri.toString());
return Text(GoRouterState.of(context).uri.path);
});
},
routes: <GoRoute>[
GoRoute(
path: 'a',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text(
key: key, GoRouterState.of(context).uri.toString());
return Text(key: key, GoRouterState.of(context).uri.path);
});
}),
]),
];
final GoRouter router =
await createRouter(routes, tester, initialLocation: '/a?p=123');
expect(tester.widget<Text>(find.byKey(key)).data, '/a?p=123');
await createRouter(routes, tester, initialLocation: '/a');
expect(tester.widget<Text>(find.byKey(key)).data, '/a');
final GoRouterStateRegistry registry = tester
.widget<GoRouterStateRegistryScope>(
find.byType(GoRouterStateRegistryScope))
Expand All @@ -136,7 +135,7 @@ void main() {
await tester.pump();
expect(registry.registry.length, 2);
// should retain the same location even if the location has changed.
expect(tester.widget<Text>(find.byKey(key)).data, '/a?p=123');
expect(tester.widget<Text>(find.byKey(key)).data, '/a');

// Finish the pop animation.
await tester.pumpAndSettle();
Expand All @@ -153,23 +152,22 @@ void main() {
path: '/',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text(GoRouterState.of(context).uri.toString());
return Text(GoRouterState.of(context).uri.path);
});
},
routes: <GoRoute>[
GoRoute(
path: 'a',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text(
key: key, GoRouterState.of(context).uri.toString());
return Text(key: key, GoRouterState.of(context).uri.path);
});
}),
]),
];
await createRouter(routes, tester,
initialLocation: '/a?p=123', navigatorKey: nav);
expect(tester.widget<Text>(find.byKey(key)).data, '/a?p=123');
initialLocation: '/a', navigatorKey: nav);
expect(tester.widget<Text>(find.byKey(key)).data, '/a');
final GoRouterStateRegistry registry = tester
.widget<GoRouterStateRegistryScope>(
find.byType(GoRouterStateRegistryScope))
Expand All @@ -179,7 +177,7 @@ void main() {
await tester.pump();
expect(registry.registry.length, 2);
// should retain the same location even if the location has changed.
expect(tester.widget<Text>(find.byKey(key)).data, '/a?p=123');
expect(tester.widget<Text>(find.byKey(key)).data, '/a');

// Finish the pop animation.
await tester.pumpAndSettle();
Expand Down
4 changes: 4 additions & 0 deletions packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.5.1

- Updates examples to use uri.path instead of uri.toString() for accessing the current location.

## 2.5.0

* Updates minimum supported SDK version to Flutter 3.13/Dart 3.1.
Expand Down
28 changes: 15 additions & 13 deletions packages/go_router_builder/example/lib/all_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BigIntRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('BigIntRoute'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand All @@ -84,7 +84,7 @@ class BoolRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('BoolRoute'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand All @@ -107,7 +107,7 @@ class DateTimeRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('DateTimeRoute'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand All @@ -133,7 +133,7 @@ class DoubleRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('DoubleRoute'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand All @@ -159,7 +159,7 @@ class IntRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('IntRoute'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand All @@ -185,7 +185,7 @@ class NumRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('NumRoute'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand All @@ -212,7 +212,7 @@ class EnumRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('EnumRoute'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand All @@ -239,7 +239,7 @@ class EnhancedEnumRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('EnhancedEnumRoute'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand All @@ -265,7 +265,7 @@ class StringRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('StringRoute'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand All @@ -288,7 +288,7 @@ class UriRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('UriRoute'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand Down Expand Up @@ -361,7 +361,7 @@ class IterableRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('IterableRoute'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand Down Expand Up @@ -430,7 +430,7 @@ class IterableRouteWithDefaultValues extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('IterableRouteWithDefaultValues'),
onTap: () => go(context),
selected: GoRouterState.of(context).uri.toString() == location,
selected: GoRouterState.of(context).uri.path == location,
);
}

Expand Down Expand Up @@ -536,7 +536,9 @@ class BasePage<T> extends StatelessWidget {
Text(
'Query param with default value: $queryParamWithDefaultValue',
),
SelectableText(GoRouterState.of(context).uri.toString()),
SelectableText(GoRouterState.of(context).uri.path),
SelectableText(
GoRouterState.of(context).uri.queryParameters.toString()),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MyShellRouteScreen extends StatelessWidget {
final Widget child;

int getCurrentIndex(BuildContext context) {
final String location = GoRouterState.of(context).uri.toString();
final String location = GoRouterState.of(context).uri.path;
if (location == '/bar') {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MyShellRouteScreen extends StatelessWidget {
final Widget child;

int getCurrentIndex(BuildContext context) {
final String location = GoRouterState.of(context).uri.toString();
final String location = GoRouterState.of(context).uri.path;
if (location.startsWith('/users')) {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class MyShellRouteScreen extends StatelessWidget {
final Widget child;

int getCurrentIndex(BuildContext context) {
final String location = GoRouterState.of(context).uri.toString();
final String location = GoRouterState.of(context).uri.path;
if (location.startsWith('/users')) {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ void main() {
).go(scaffoldState.context);
await tester.pumpAndSettle();
expect(find.text('IterableRoute'), findsOneWidget);
expect(find.text('/iterable-route'), findsOneWidget);
expect(
find.text(
'/iterable-route?enum-iterable-field=football&int-list-field=1&int-list-field=2&int-list-field=3&enum-only-in-set-field=burger&enum-only-in-set-field=pizza'),
'{enum-iterable-field: football, int-list-field: 3, enum-only-in-set-field: pizza}'),
findsOneWidget);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/go_router_builder/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: go_router_builder
description: >-
A builder that supports generated strongly-typed route helpers for
package:go_router
version: 2.5.0
version: 2.5.1
repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22

Expand Down