-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[go_router_builder] Adds support for required $extra parameter #3627
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
950b91a
adds support for required extra
dancamdev a443a8b
lint fixes
dancamdev 21cf5f6
format fixes
dancamdev 72cdcb5
fix license
dancamdev 08ba587
Merge branch 'main' into feature/required-extra
dancamdev 66c70a1
Merge branch 'main' into feature/required-extra
dancamdev 8f8acd9
fix: [feature/required-extra] fix linter and add changelog link
Michele-x98 40b93d6
lint fixes
dancamdev d4d2a2c
fixed test
dancamdev 192bf67
re-adds analyzer fixes
dancamdev 028ec7a
Update extra_example.g.dart
Michele-x98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 1.2.1 | ||
|
||
* Supports opt-in required extra parameters. [#117261] | ||
|
||
## 1.2.0 | ||
|
||
* Adds Support for ShellRoute | ||
|
123 changes: 123 additions & 0 deletions
123
packages/go_router_builder/example/lib/extra_example.dart
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,123 @@ | ||
// 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, always_specify_types | ||
dancamdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
part 'extra_example.g.dart'; | ||
|
||
void main() => runApp(const App()); | ||
|
||
final GoRouter _router = GoRouter( | ||
routes: $appRoutes, | ||
initialLocation: '/splash', | ||
); | ||
|
||
class App extends StatelessWidget { | ||
const App({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp.router( | ||
routerConfig: _router, | ||
); | ||
} | ||
} | ||
|
||
class Extra { | ||
const Extra(this.value); | ||
|
||
final int value; | ||
} | ||
|
||
@TypedGoRoute<RequiredExtraRoute>(path: '/requiredExtra') | ||
class RequiredExtraRoute extends GoRouteData { | ||
const RequiredExtraRoute({required this.$extra}); | ||
|
||
final Extra $extra; | ||
|
||
@override | ||
Widget build(BuildContext context, GoRouterState state) => | ||
RequiredExtraScreen(extra: $extra); | ||
} | ||
|
||
class RequiredExtraScreen extends StatelessWidget { | ||
const RequiredExtraScreen({super.key, required this.extra}); | ||
|
||
final Extra extra; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Required Extra')), | ||
body: Center(child: Text('Extra: ${extra.value}')), | ||
); | ||
} | ||
} | ||
|
||
@TypedGoRoute<OptionalExtraRoute>(path: '/optionalExtra') | ||
class OptionalExtraRoute extends GoRouteData { | ||
const OptionalExtraRoute({this.$extra}); | ||
|
||
final Extra? $extra; | ||
|
||
@override | ||
Widget build(BuildContext context, GoRouterState state) => | ||
OptionalExtraScreen(extra: $extra); | ||
} | ||
|
||
class OptionalExtraScreen extends StatelessWidget { | ||
const OptionalExtraScreen({super.key, this.extra}); | ||
|
||
final Extra? extra; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Optional Extra')), | ||
body: Center(child: Text('Extra: ${extra?.value}')), | ||
); | ||
} | ||
} | ||
|
||
@TypedGoRoute<SplashRoute>(path: '/splash') | ||
class SplashRoute extends GoRouteData { | ||
const SplashRoute(); | ||
|
||
@override | ||
Widget build(BuildContext context, GoRouterState state) => const Splash(); | ||
} | ||
|
||
class Splash extends StatelessWidget { | ||
const Splash({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Splash')), | ||
body: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
const Placeholder(), | ||
ElevatedButton( | ||
onPressed: () => | ||
const RequiredExtraRoute($extra: Extra(1)).go(context), | ||
child: const Text('Required Extra'), | ||
), | ||
ElevatedButton( | ||
onPressed: () => | ||
const OptionalExtraRoute($extra: Extra(2)).go(context), | ||
child: const Text('Optional Extra'), | ||
), | ||
ElevatedButton( | ||
onPressed: () => const OptionalExtraRoute().go(context), | ||
child: const Text('Optional Extra (null)'), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
packages/go_router_builder/example/lib/extra_example.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.