Skip to content
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
37be48c
- Adds `GoRouter.goRelative`
ThangVuNguyenViet May 29, 2024
f8061ce
add go_relative example for go_router
ThangVuNguyenViet May 29, 2024
8a77147
add go_relative_test for the example
ThangVuNguyenViet May 29, 2024
61127f3
fix failed test
ThangVuNguyenViet May 29, 2024
687b332
replace goRelative with go('./$path')
ThangVuNguyenViet Jun 19, 2024
cca1454
Commit missing files during merge
ThangVuNguyenViet Jun 19, 2024
975128b
update changelog & version
ThangVuNguyenViet Jun 19, 2024
6d90488
Prevent concatenateUris from adding trailing redundant '?'. Add test …
ThangVuNguyenViet Jun 19, 2024
ccb38f9
Add more `concatenateUris` test. Fix joining params
ThangVuNguyenViet Jun 19, 2024
80d85d6
update example description
ThangVuNguyenViet Jul 10, 2024
a09aa94
Make concatenateUris not merging parameters, only take them from chil…
ThangVuNguyenViet Jul 19, 2024
a174cbe
Add GoRelativeRouteConfig
ThangVuNguyenViet Jul 10, 2024
4cb0334
Add test, examples and example tests for go_router_builder. Temporari…
ThangVuNguyenViet Jul 19, 2024
ceaa318
Add relativeLocation, push, pushReplacement & replace to the Relative…
ThangVuNguyenViet Jul 19, 2024
d3b5355
Merge branch 'flutter-main'
ThangVuNguyenViet Jan 22, 2025
07b4a23
update go_router package dependency
ThangVuNguyenViet Jan 22, 2025
6008b8b
Fix merge issues
ThangVuNguyenViet Jan 22, 2025
d2fbc0e
temporarily add dependency_override
ThangVuNguyenViet Jan 22, 2025
8b5fb4d
change relative route actions to have suffix `Relative`
ThangVuNguyenViet Feb 3, 2025
02c3d7b
Fix example
ThangVuNguyenViet Feb 4, 2025
72c06de
Update go_relative test
ThangVuNguyenViet Feb 6, 2025
edef7a5
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet May 17, 2025
5474303
fix generated file
ThangVuNguyenViet May 17, 2025
dbf7f9d
Fix failed test due to generated files
ThangVuNguyenViet May 17, 2025
37c5490
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jun 2, 2025
868a2d5
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jun 12, 2025
232dc7d
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jul 1, 2025
1d5ad11
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jul 9, 2025
f899939
Remove GoRouteData routing methods. Update TypedRelativeGoRoute gener…
ThangVuNguyenViet Jul 9, 2025
92f6cac
remove overrides on other tests
ThangVuNguyenViet Jul 9, 2025
f98505e
make sure relative go route generated code resembles typed go route a…
ThangVuNguyenViet Jul 9, 2025
20fd5d6
update changelog
ThangVuNguyenViet Jul 10, 2025
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 @@
## 14.6.5

- Adds `TypedRelativeGoRoute`

## 14.6.4

- Rephrases readme.
Expand Down
22 changes: 22 additions & 0 deletions packages/go_router/lib/src/route_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,28 @@ class TypedGoRoute<T extends GoRouteData> extends TypedRoute<T> {
final List<TypedRoute<RouteData>> routes;
}

/// A superclass for each typed go route descendant
@Target(<TargetKind>{TargetKind.library, TargetKind.classType})
class TypedRelativeGoRoute<T extends GoRouteData> extends TypedRoute<T> {
/// Default const constructor
const TypedRelativeGoRoute({
required this.path,
this.routes = const <TypedRoute<RouteData>>[],
});

/// The relative path that corresponds to this route.
///
/// See [GoRoute.path].
///
///
final String path;

/// Child route definitions.
///
/// See [RouteBase.routes].
final List<TypedRoute<RouteData>> routes;
}

/// A superclass for each typed shell route descendant
@Target(<TargetKind>{TargetKind.library, TargetKind.classType})
class TypedShellRoute<T extends ShellRouteData> extends TypedRoute<T> {
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: 14.6.4
version: 14.6.5
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
3 changes: 3 additions & 0 deletions packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.7.4

- Adds `TypedRelativeGoRoute` annotation which supports relative routes.

## 2.7.3

Expand Down
156 changes: 156 additions & 0 deletions packages/go_router_builder/example/lib/go_relative.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs, unreachable_from_main

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

part 'go_relative.g.dart';

void main() => runApp(const MyApp());

/// The main app.
class MyApp extends StatelessWidget {
/// Constructs a [MyApp]
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: _router,
);
}
}

/// The route configuration.
final GoRouter _router = GoRouter(
routes: $appRoutes,
);
const TypedRelativeGoRoute<DetailsRoute> detailRoute =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is different between using this vs a regular TypedGoRoute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example I gave isn't clearly explaining the purpose. Let me update this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still can't see the difference. Is this a way to reuse the typedGoRoute in multiple places in the routing tree?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Without this you'd have to define routes like
SettingsFromHomeRoute
SettingsFromDashboardRoute

And those routes all build (or build page) the same screen

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this makes sense. I will take another look

TypedRelativeGoRoute<DetailsRoute>(
path: 'details/:detailId',
routes: <TypedRoute<RouteData>>[
TypedRelativeGoRoute<SettingsRoute>(path: 'settings/:settingId'),
],
);

@TypedGoRoute<HomeRoute>(
path: '/',
routes: <TypedRoute<RouteData>>[detailRoute],
)
class HomeRoute extends GoRouteData {
@override
Widget build(BuildContext context, GoRouterState state) {
return const HomeScreen();
}
}

class DetailsRoute extends GoRouteData {
const DetailsRoute({required this.detailId});
final String detailId;

@override
Widget build(BuildContext context, GoRouterState state) {
return DetailsScreen(id: detailId);
}
}

class SettingsRoute extends GoRouteData {
const SettingsRoute({
required this.settingId,
});
final String settingId;

@override
Widget build(BuildContext context, GoRouterState state) {
return SettingsScreen(id: settingId);
}
}

/// The home screen
class HomeScreen extends StatefulWidget {
/// Constructs a [HomeScreen]
const HomeScreen({super.key});

@override
State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Home Screen')),
body: Center(
child: ElevatedButton(
onPressed: () {
const DetailsRoute(detailId: 'DetailsId').goRelative(context);
},
child: const Text('Go to the Details screen'),
),
),
);
}
}

/// The details screen
class DetailsScreen extends StatelessWidget {
/// Constructs a [DetailsScreen]
const DetailsScreen({
super.key,
required this.id,
});

final String id;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Details Screen $id')),
body: Center(
child: Column(
children: <Widget>[
ElevatedButton(
onPressed: () => HomeRoute().go(context),
child: const Text('Go back'),
),
ElevatedButton(
onPressed: () => const SettingsRoute(
settingId: 'SettingsId',
).goRelative(context),
child: const Text('Go to the Settings screen'),
),
],
),
),
);
}
}

/// The details screen
class SettingsScreen extends StatelessWidget {
/// Constructs a [SettingsScreen]
const SettingsScreen({
super.key,
required this.id,
});

final String id;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Settings Screen $id')),
body: Center(
child: TextButton(
onPressed: () {
context.pop();
},
child: const Text('Go back'),
),
),
);
}
}
89 changes: 89 additions & 0 deletions packages/go_router_builder/example/lib/go_relative.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/go_router_builder/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ dev_dependencies:
path: ..
test: ^1.17.0

dependency_overrides:
go_router:
path: ../../go_router

flutter:
uses-material-design: true
29 changes: 29 additions & 0 deletions packages/go_router_builder/example/test/go_relative_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:go_router_builder_example/go_relative.dart' as example;

void main() {
testWidgets('example works', (WidgetTester tester) async {
await tester.pumpWidget(const example.MyApp());
expect(find.byType(example.HomeScreen), findsOneWidget);

await tester.tap(find.text('Go to the Details screen'));
await tester.pumpAndSettle();
expect(find.byType(example.DetailsScreen), findsOneWidget);

await tester.tap(find.text('Go to the Settings screen'));
await tester.pumpAndSettle();
expect(find.byType(example.SettingsScreen), findsOneWidget);

await tester.tap(find.text('Go back'));
await tester.pumpAndSettle();
expect(find.byType(example.DetailsScreen), findsOneWidget);

await tester.tap(find.text('Go back'));
await tester.pumpAndSettle();
expect(find.byType(example.HomeScreen), findsOneWidget);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const String _routeDataUrl = 'package:go_router/src/route_data.dart';

const Map<String, String> _annotations = <String, String>{
'TypedGoRoute': 'GoRouteData',
'TypedRelativeRoute': 'GoRouteData',
'TypedShellRoute': 'ShellRouteData',
'TypedStatefulShellBranch': 'StatefulShellBranchData',
'TypedStatefulShellRoute': 'StatefulShellRouteData',
Expand Down
Loading