-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[flutter_adaptive_scaffold] Go router sample for AdaptiveScaffold #7452
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 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e09cd27
Add go_router sample
martijn00 c1da62a
Fix path
martijn00 3abe332
Fix routes
martijn00 42cc486
Delete
martijn00 627211f
Depend on local
martijn00 b7340c7
Fix
martijn00 2d05bb1
Fixes
martijn00 797fd32
Fix redirect
martijn00 a36df7e
Fixes
martijn00 2cd8bec
Fixes
martijn00 894c7f2
Fix passing of parameter
martijn00 83ba47c
Fixes
martijn00 7161e61
Fix
martijn00 47262a5
Docs
martijn00 b259d3d
Pin version
martijn00 43a39fe
Update packages/flutter_adaptive_scaffold/example/lib/go_router_demo/…
martijn00 2848028
License
martijn00 923f3c7
Readme
martijn00 e09706b
Changelog
martijn00 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
33 changes: 33 additions & 0 deletions
33
packages/flutter_adaptive_scaffold/example/lib/go_router_demo.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,33 @@ | ||
| // 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 'go_router_demo/app_router.dart'; | ||
|
|
||
| void main() { | ||
| runApp(const MyApp()); | ||
| } | ||
|
|
||
| /// The main application widget for this example. | ||
| class MyApp extends StatelessWidget { | ||
| /// Creates a const main application widget. | ||
| const MyApp({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp.router( | ||
| restorationScopeId: 'demo', | ||
| routerConfig: AppRouter.router, | ||
| theme: ThemeData( | ||
| colorScheme: ColorScheme.fromSeed( | ||
| seedColor: Colors.blue, | ||
| dynamicSchemeVariant: DynamicSchemeVariant.vibrant, | ||
| primary: Colors.blue, | ||
| ), | ||
| useMaterial3: true, | ||
| ), | ||
| ); | ||
| } | ||
| } |
193 changes: 193 additions & 0 deletions
193
packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.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,193 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:go_router/go_router.dart'; | ||
|
|
||
| import 'pages/pages.dart'; | ||
| import 'scaffold_shell.dart'; | ||
|
|
||
| /// The root navigator key for the main router of the app. | ||
| final GlobalKey<NavigatorState> rootNavigatorKey = | ||
| GlobalKey<NavigatorState>(debugLabel: 'root'); | ||
|
|
||
| final GlobalKey<NavigatorState> _homeNavigatorKey = | ||
| GlobalKey<NavigatorState>(debugLabel: 'home'); | ||
| final GlobalKey<NavigatorState> _counterNavigatorKey = | ||
| GlobalKey<NavigatorState>(debugLabel: 'counter'); | ||
| final GlobalKey<NavigatorState> _moreNavigatorKey = | ||
| GlobalKey<NavigatorState>(debugLabel: 'more'); | ||
|
|
||
| /// The [AppRouter] maintains the main route configuration for the app. | ||
| /// | ||
| /// Routes that are `fullScreenDialogs` should also set `_rootNavigatorKey` as | ||
| /// the `parentNavigatorKey` to ensure that the dialog is displayed correctly. | ||
| class AppRouter { | ||
| /// The authentication status of the user. | ||
| static ValueNotifier<bool> authenticatedNotifier = ValueNotifier<bool>(false); | ||
|
|
||
| /// The router with the routes of pages that should be displayed. | ||
| static final GoRouter router = GoRouter( | ||
| navigatorKey: rootNavigatorKey, | ||
| debugLogDiagnostics: true, | ||
| errorPageBuilder: (BuildContext context, GoRouterState state) { | ||
| return const MaterialPage<void>(child: NavigationErrorPage()); | ||
| }, | ||
| redirect: (BuildContext context, GoRouterState state) { | ||
| if (state.uri.path == '/') { | ||
| return HomePage.path; | ||
| } | ||
| return null; | ||
| }, | ||
| refreshListenable: authenticatedNotifier, | ||
| routes: <RouteBase>[ | ||
| _unauthenticatedRoutes, | ||
| _authenticatedRoutes, | ||
| ..._openRoutes, | ||
| ], | ||
| ); | ||
|
|
||
| static final GoRoute _unauthenticatedRoutes = GoRoute( | ||
| name: LoginPage.name, | ||
| path: LoginPage.path, | ||
| pageBuilder: (BuildContext context, GoRouterState state) { | ||
| return const MaterialPage<void>(child: LoginPage()); | ||
| }, | ||
| redirect: (BuildContext context, GoRouterState state) { | ||
| if (authenticatedNotifier.value) { | ||
| return HomePage.path; | ||
| } | ||
| return null; | ||
| }, | ||
| routes: <RouteBase>[ | ||
| GoRoute( | ||
| name: ForgotPasswordPage.name, | ||
| path: ForgotPasswordPage.path, | ||
| pageBuilder: (BuildContext context, GoRouterState state) { | ||
| return const MaterialPage<void>( | ||
| child: ForgotPasswordPage(), | ||
| ); | ||
| }, | ||
| ), | ||
| ], | ||
| ); | ||
|
|
||
| static final StatefulShellRoute _authenticatedRoutes = | ||
| StatefulShellRoute.indexedStack( | ||
| parentNavigatorKey: rootNavigatorKey, | ||
| builder: ( | ||
| BuildContext context, | ||
| GoRouterState state, | ||
| StatefulNavigationShell navigationShell, | ||
| ) { | ||
| return ScaffoldShell(navigationShell: navigationShell); | ||
| }, | ||
| redirect: (BuildContext context, GoRouterState state) { | ||
| if (!authenticatedNotifier.value) { | ||
| return LoginPage.path; | ||
| } | ||
| return null; | ||
| }, | ||
| branches: <StatefulShellBranch>[ | ||
| StatefulShellBranch( | ||
| navigatorKey: _homeNavigatorKey, | ||
| routes: <RouteBase>[ | ||
| GoRoute( | ||
| name: HomePage.name, | ||
| path: HomePage.path, | ||
| pageBuilder: (BuildContext context, GoRouterState state) { | ||
| return const NoTransitionPage<void>( | ||
| child: HomePage(), | ||
| ); | ||
| }, | ||
| routes: <RouteBase>[ | ||
| GoRoute( | ||
| name: DetailOverviewPage.name, | ||
| path: DetailOverviewPage.path, | ||
| pageBuilder: (BuildContext context, GoRouterState state) { | ||
| return const MaterialPage<void>( | ||
| child: DetailOverviewPage(), | ||
| ); | ||
| }, | ||
| routes: <RouteBase>[ | ||
| GoRoute( | ||
| name: DetailPage.name, | ||
| path: DetailPage.path, | ||
| pageBuilder: (BuildContext context, GoRouterState state) { | ||
| return MaterialPage<void>( | ||
| child: DetailPage( | ||
| itemName: state.uri.queryParameters['itemName']!), | ||
| ); | ||
| }, | ||
| ), | ||
| ]), | ||
| GoRoute( | ||
| name: DetailModalPage.name, | ||
| path: DetailModalPage.path, | ||
| parentNavigatorKey: rootNavigatorKey, | ||
| pageBuilder: (BuildContext context, GoRouterState state) { | ||
| return const MaterialPage<void>( | ||
| fullscreenDialog: true, | ||
| child: DetailModalPage(), | ||
| ); | ||
| }, | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| StatefulShellBranch( | ||
| navigatorKey: _counterNavigatorKey, | ||
| routes: <RouteBase>[ | ||
| GoRoute( | ||
| name: CounterPage.name, | ||
| path: CounterPage.path, | ||
| pageBuilder: (BuildContext context, GoRouterState state) { | ||
| return const NoTransitionPage<void>(child: CounterPage()); | ||
| }, | ||
| ), | ||
| ], | ||
| ), | ||
| StatefulShellBranch( | ||
| navigatorKey: _moreNavigatorKey, | ||
| routes: <RouteBase>[ | ||
| GoRoute( | ||
| name: MorePage.name, | ||
| path: MorePage.path, | ||
| pageBuilder: (BuildContext context, GoRouterState state) { | ||
| return const NoTransitionPage<void>( | ||
| key: ValueKey<String>(MorePage.name), | ||
| child: MorePage(), | ||
| ); | ||
| }, | ||
| routes: <RouteBase>[ | ||
| GoRoute( | ||
| path: ProfilePage.path, | ||
| name: ProfilePage.name, | ||
| pageBuilder: (BuildContext context, GoRouterState state) { | ||
| return const MaterialPage<void>(child: ProfilePage()); | ||
| }, | ||
| ), | ||
| GoRoute( | ||
| name: SettingsPage.name, | ||
| path: SettingsPage.path, | ||
| pageBuilder: (BuildContext context, GoRouterState state) { | ||
| return const MaterialPage<void>(child: SettingsPage()); | ||
| }, | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ); | ||
|
|
||
| static final List<GoRoute> _openRoutes = <GoRoute>[ | ||
| GoRoute( | ||
| name: LanguagePage.name, | ||
| path: LanguagePage.path, | ||
| pageBuilder: (BuildContext context, GoRouterState state) { | ||
| return const MaterialPage<void>( | ||
| child: LanguagePage(), | ||
| ); | ||
| }, | ||
| ), | ||
| ]; | ||
| } |
25 changes: 25 additions & 0 deletions
25
packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart
martijn00 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
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,25 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| /// The counter page. | ||
| class CounterPage extends StatelessWidget { | ||
| /// Construct the counter page. | ||
| const CounterPage({super.key}); | ||
|
|
||
| /// The path for the counter page. | ||
| static const String path = '/counter'; | ||
|
|
||
| /// The name for the counter page. | ||
| static const String name = 'Counter'; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: const Text('Counter Page'), | ||
| ), | ||
| body: const Center( | ||
| child: Text('Counter Page'), | ||
| ), | ||
| ); | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.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,25 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| /// The detail modal page. | ||
| class DetailModalPage extends StatelessWidget { | ||
| /// Construct the detail modal page. | ||
| const DetailModalPage({super.key}); | ||
|
|
||
| /// The path for the detail modal page. | ||
| static const String path = 'detail-modal'; | ||
|
|
||
| /// The name for the detail modal page. | ||
| static const String name = 'DetailModal'; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: const Text('Detail Modal Page'), | ||
| ), | ||
| body: const Center( | ||
| child: Text('Detail modal Page'), | ||
| ), | ||
| ); | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
...ages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.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,39 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:go_router/go_router.dart'; | ||
|
|
||
| import 'detail_page.dart'; | ||
|
|
||
| /// The detail overview page. | ||
| class DetailOverviewPage extends StatelessWidget { | ||
| /// Construct the detail overview page. | ||
| const DetailOverviewPage({super.key}); | ||
|
|
||
| /// The path for the detail page. | ||
| static const String path = 'detail-overview'; | ||
|
|
||
| /// The name for the detail page. | ||
| static const String name = 'DetailOverview'; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: const Text('Detail Overview Page'), | ||
| ), | ||
| body: ListView.builder( | ||
| itemCount: 10, | ||
| itemBuilder: (BuildContext context, int index) { | ||
| return ListTile( | ||
| title: Text('Item $index'), | ||
| onTap: () { | ||
| context.goNamed( | ||
| DetailPage.name, | ||
| queryParameters: <String, String>{'itemName': '$index'}, | ||
| ); | ||
| }, | ||
| ); | ||
| }, | ||
| ), | ||
| ); | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.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,28 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| /// The detail page. | ||
| class DetailPage extends StatelessWidget { | ||
| /// Construct the detail page. | ||
| const DetailPage({super.key, required this.itemName}); | ||
|
|
||
| /// The path for the detail page. | ||
| static const String path = 'detail'; | ||
|
|
||
| /// The name for the detail page. | ||
| static const String name = 'Detail'; | ||
|
|
||
| /// The item name for the detail page. | ||
| final String itemName; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: const Text('Detail Page'), | ||
| ), | ||
| body: Center( | ||
| child: Text('Detail Page: $itemName'), | ||
| ), | ||
| ); | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
...ages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.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,25 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| /// The forgot password page. | ||
| class ForgotPasswordPage extends StatelessWidget { | ||
| /// Construct the forgot password page. | ||
| const ForgotPasswordPage({super.key}); | ||
|
|
||
| /// The path for the forgot password page. | ||
| static const String path = 'forgot_password'; | ||
|
|
||
| /// The name for the forgot password page. | ||
| static const String name = 'ForgotPassword'; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: const Text('Forgot Password'), | ||
| ), | ||
| body: const Center( | ||
| child: Text('ForgotPassword Page'), | ||
| ), | ||
| ); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.