forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[go_router_builder] Adds support for required $extra parameter (flutt…
…er#3627) [go_router_builder] Adds support for required $extra parameter
- Loading branch information
Showing
8 changed files
with
250 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
123 changes: 123 additions & 0 deletions
123
packages/go_router_builder/example/lib/extra_example.dart
This file contains 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 | ||
|
||
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: <Widget>[ | ||
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 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 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 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 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 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