-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[go_router_builder] Add support for relative routes #7174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
37be48c
- Adds `GoRouter.goRelative`
ThangVuNguyenViet f8061ce
add go_relative example for go_router
ThangVuNguyenViet 8a77147
add go_relative_test for the example
ThangVuNguyenViet 61127f3
fix failed test
ThangVuNguyenViet 687b332
replace goRelative with go('./$path')
ThangVuNguyenViet cca1454
Commit missing files during merge
ThangVuNguyenViet 975128b
update changelog & version
ThangVuNguyenViet 6d90488
Prevent concatenateUris from adding trailing redundant '?'. Add test …
ThangVuNguyenViet ccb38f9
Add more `concatenateUris` test. Fix joining params
ThangVuNguyenViet 80d85d6
update example description
ThangVuNguyenViet a09aa94
Make concatenateUris not merging parameters, only take them from chil…
ThangVuNguyenViet a174cbe
Add GoRelativeRouteConfig
ThangVuNguyenViet 4cb0334
Add test, examples and example tests for go_router_builder. Temporari…
ThangVuNguyenViet ceaa318
Add relativeLocation, push, pushReplacement & replace to the Relative…
ThangVuNguyenViet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// 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/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
/// This sample app demonstrates how to use go relatively with GoRouter.go('./$path'). | ||
void main() => runApp(const MyApp()); | ||
|
||
/// The route configuration. | ||
final GoRouter _router = GoRouter( | ||
routes: <RouteBase>[ | ||
GoRoute( | ||
path: '/', | ||
builder: (BuildContext context, GoRouterState state) { | ||
return const HomeScreen(); | ||
}, | ||
routes: <RouteBase>[ | ||
GoRoute( | ||
path: 'details', | ||
builder: (BuildContext context, GoRouterState state) { | ||
return const DetailsScreen(); | ||
}, | ||
routes: <RouteBase>[ | ||
GoRoute( | ||
path: 'settings', | ||
builder: (BuildContext context, GoRouterState state) { | ||
return const SettingsScreen(); | ||
}, | ||
), | ||
], | ||
), | ||
], | ||
), | ||
], | ||
); | ||
|
||
/// 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 home screen | ||
class HomeScreen extends StatelessWidget { | ||
/// Constructs a [HomeScreen] | ||
const HomeScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Home Screen')), | ||
body: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
ElevatedButton( | ||
onPressed: () => context.go('./details'), | ||
child: const Text('Go to the Details screen'), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
/// The details screen | ||
class DetailsScreen extends StatelessWidget { | ||
/// Constructs a [DetailsScreen] | ||
const DetailsScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Details Screen')), | ||
body: Center( | ||
child: Column( | ||
children: <Widget>[ | ||
TextButton( | ||
onPressed: () { | ||
context.pop(); | ||
}, | ||
child: const Text('go back'), | ||
), | ||
TextButton( | ||
onPressed: () { | ||
context.go('./settings'); | ||
}, | ||
child: const Text('Go to the Settings screen'), | ||
), | ||
], | ||
)), | ||
); | ||
} | ||
} | ||
|
||
/// The settings screen | ||
class SettingsScreen extends StatelessWidget { | ||
/// Constructs a [SettingsScreen] | ||
const SettingsScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Settings Screen')), | ||
body: const Center( | ||
child: Text('Settings'), | ||
), | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// 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_examples/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); | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see the difference between this and
TypedGoRoute
it seems to me that if user uses go_router_builder they are not using url string to navigate so they don't really need relative routing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well they won't be using './$path' directly, but they'll use
route.goRelative()
, which uses that under the hood.Not sure if I got your question right thou..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant they could define a TypedGoRoute directly and do GoRouteData.go, why would they want to define a TypedRelativeRoute ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can't define TypedGoRoute in multiple places. Take the example in the description, the relativeRoute was declared in a variable and passed in 2 routes. Had that been normal TypedGoRoute, it would've produced 2 extensions with the same name, of which locations are different, and results in build time error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be two different feature right?
go('./relative')
and 2 needs to build on top of 1.
If so I think we should separate the 2 into a new pr to make review simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh looks like you already did #6825.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay... so do I need to change anything else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest removing the TypeRelativeRoute from #6825 and do all the TypeRelativeRoute thing in a separate pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypedRelativeRoute needs to be landed in order for this PR to work. The reason this PR is working right now is because of the
dependency_overrides
, which I meant to remove after the #6825 is merged. Can you suggest how do I remove the TypedRelativeRoute? Do I create a PR with onlyTypedRelativeRoute
declaration, wait for it to get merged and then continue with this PR?Imo it's feels weird to me that an annotation of a builder package belongs to the main package and not in the builder package, but maybe there is a technical reason for that that I don't know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I meant the TypedRelativeRoute should be separate from #6825 since they are not related. and then we can review and merge #6825 first before we review TypedRelativeRoute separately.