From e09cd27f79d17415a85332363f4e40c8073c92e1 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Mon, 19 Aug 2024 16:55:16 +0200 Subject: [PATCH 01/19] Add go_router sample --- .../example/lib/go_router_demo.dart | 25 +++ .../lib/go_router_demo/global_router.dart | 51 ++++++ .../go_router_demo/pages/counter_page.dart | 17 ++ .../pages/detail_modal_page.dart | 17 ++ .../lib/go_router_demo/pages/detail_page.dart | 17 ++ .../pages/forgot_password_page.dart | 17 ++ .../lib/go_router_demo/pages/home_page.dart | 17 ++ .../go_router_demo/pages/language_page.dart | 17 ++ .../lib/go_router_demo/pages/login_page.dart | 17 ++ .../lib/go_router_demo/pages/more_page.dart | 17 ++ .../pages/navigation_error_page.dart | 17 ++ .../lib/go_router_demo/pages/pages.dart | 11 ++ .../go_router_demo/pages/profile_page.dart | 17 ++ .../go_router_demo/pages/settings_page.dart | 17 ++ .../example/lib/go_router_demo/routes.dart | 148 ++++++++++++++++++ .../lib/go_router_demo/scaffold_shell.dart | 47 ++++++ .../example/pubspec.yaml | 3 +- .../lib/src/navigation_suite_scaffold.dart | 31 ++++ 18 files changed, 502 insertions(+), 1 deletion(-) create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart create mode 100644 packages/flutter_adaptive_scaffold/lib/src/navigation_suite_scaffold.dart diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart new file mode 100644 index 00000000000..c84d6885fbb --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart @@ -0,0 +1,25 @@ +// 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/global_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: GlobalRouter.router, + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart new file mode 100644 index 00000000000..0e614d21498 --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; + +import 'pages/pages.dart'; +import 'routes.dart'; + +/// The root navigator key for the main router of the app. +final GlobalKey rootNavigatorKey = + GlobalKey(debugLabel: 'root'); + +/// The [GlobalRouter] 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 GlobalRouter { + /// The router with the routes of pages that should be displayed. + static final GoRouter router = GoRouter( + navigatorKey: rootNavigatorKey, + errorPageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage(child: NavigationErrorPage()); + }, + redirect: (BuildContext context, GoRouterState state) async { + // Check if the route we want navigate to is a shared route, so we don't + // need to check auth status. + if (Routes.commonRoutes.any( + (GoRoute e) => state.fullPath?.contains(e.path) ?? false, + )) { + return null; + } + + // TODO: Implement authentication status check + final bool authenticated = false; + + //TODO: check unauthenticated routes + // if (!authenticated && routes.unauthenticatedRoutes.any(state.fullPath) + // return null; + // else if(!authenticated) + // return LoginPage.path; + // else if(authenticated && state.fullPath == LoginPage.path) + // return HomePage.path; + + // In any other case the redirect can be safely ignored and handled as is. + return null; + }, + routes: [ + Routes.unauthenticatedRoutes, + Routes.authenticatedRoutes, + ...Routes.commonRoutes, + ], + ); +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart new file mode 100644 index 00000000000..0b1ec0d5792 --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class CounterPage extends StatelessWidget { + const CounterPage({Key? key}) : super(key: key); + + static const String path = '/counter'; + static const String name = 'Counter'; + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: Text('Counter Page'), + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart new file mode 100644 index 00000000000..ad069d986d4 --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class DetailModalPage extends StatelessWidget { + const DetailModalPage({Key? key}) : super(key: key); + + static const String path = '/detail-modal'; + static const String name = 'DetailModal'; + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: Text('Detail modal Page'), + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart new file mode 100644 index 00000000000..565e7894e50 --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class DetailPage extends StatelessWidget { + const DetailPage({Key? key}) : super(key: key); + + static const String path = '/detail'; + static const String name = 'Detail'; + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: Text('Detail Page'), + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart new file mode 100644 index 00000000000..593c95f436e --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class ForgotPasswordPage extends StatelessWidget { + const ForgotPasswordPage({Key? key}) : super(key: key); + + static const String path = '/forgot_password'; + static const String name = 'ForgotPassword'; + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: Text('ForgotPassword Page'), + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart new file mode 100644 index 00000000000..8c6f95a4079 --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class HomePage extends StatelessWidget { + const HomePage({Key? key}) : super(key: key); + + static const String path = '/home'; + static const String name = 'Home'; + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: Text('Home Page'), + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart new file mode 100644 index 00000000000..a9bef5826a2 --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class LanguagePage extends StatelessWidget { + const LanguagePage({Key? key}) : super(key: key); + + static const String path = '/language'; + static const String name = 'Language'; + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: Text('Language Page'), + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart new file mode 100644 index 00000000000..b8950608b4d --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class LoginPage extends StatelessWidget { + const LoginPage({Key? key}) : super(key: key); + + static const String path = '/login'; + static const String name = 'Login'; + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: Text('Login Page'), + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart new file mode 100644 index 00000000000..e47393b03b8 --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class MorePage extends StatelessWidget { + const MorePage({Key? key}) : super(key: key); + + static const String path = '/more'; + static const String name = 'More'; + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: Text('More Page'), + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart new file mode 100644 index 00000000000..4a5c72f476e --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class NavigationErrorPage extends StatelessWidget { + const NavigationErrorPage({Key? key}) : super(key: key); + + static const String path = '/error'; + static const String name = 'Error'; + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: Text('Error Page'), + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart new file mode 100644 index 00000000000..55cf96ddfa2 --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart @@ -0,0 +1,11 @@ +export 'counter_page.dart'; +export 'detail_modal_page.dart'; +export 'detail_page.dart'; +export 'forgot_password_page.dart'; +export 'home_page.dart'; +export 'language_page.dart'; +export 'login_page.dart'; +export 'more_page.dart'; +export 'navigation_error_page.dart'; +export 'profile_page.dart'; +export 'settings_page.dart'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart new file mode 100644 index 00000000000..8963af332da --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class ProfilePage extends StatelessWidget { + const ProfilePage({Key? key}) : super(key: key); + + static const String path = '/profile'; + static const String name = 'Profile'; + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: Text('Profile Page'), + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart new file mode 100644 index 00000000000..5115d1b3051 --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class SettingsPage extends StatelessWidget { + const SettingsPage({Key? key}) : super(key: key); + + static const String path = '/settings'; + static const String name = 'Settings'; + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: Text('Settings Page'), + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart new file mode 100644 index 00000000000..8935f7efd7d --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart @@ -0,0 +1,148 @@ +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; +import 'global_router.dart' as router show rootNavigatorKey; + +import 'pages/pages.dart'; +import 'scaffold_shell.dart'; + +final GlobalKey _homeNavigatorKey = + GlobalKey(debugLabel: 'home'); +final GlobalKey _counterNavigatorKey = + GlobalKey(debugLabel: 'counter'); +final GlobalKey _moreNavigatorKey = + GlobalKey(debugLabel: 'more'); + +/// Stores the routes that are accessible to unauthenticated users. +class Routes { + /// The route for the login page. + static GoRoute get unauthenticatedRoutes { + return GoRoute( + name: LoginPage.name, + path: LoginPage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage(child: LoginPage()); + }, + routes: [ + GoRoute( + name: ForgotPasswordPage.name, + path: ForgotPasswordPage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage( + child: ForgotPasswordPage(), + ); + }, + ), + ], + ); + } + + /// The routes for the authenticated user. + static StatefulShellRoute get authenticatedRoutes { + return StatefulShellRoute.indexedStack( + parentNavigatorKey: router.rootNavigatorKey, + builder: ( + BuildContext context, + GoRouterState state, + StatefulNavigationShell navigationShell, + ) { + return ScaffoldShell(navigationShell: navigationShell); + }, + branches: [ + StatefulShellBranch( + navigatorKey: _homeNavigatorKey, + routes: [ + GoRoute( + name: HomePage.name, + path: HomePage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage( + child: HomePage(), + ); + }, + routes: [ + GoRoute( + name: DetailPage.name, + path: DetailPage.path, + parentNavigatorKey: router.rootNavigatorKey, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage( + child: DetailPage(), + ); + }, + ), + GoRoute( + name: DetailModalPage.name, + path: DetailModalPage.path, + parentNavigatorKey: router.rootNavigatorKey, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage( + fullscreenDialog: true, + child: DetailModalPage(), + ); + }, + ), + ], + ), + ], + ), + StatefulShellBranch( + navigatorKey: _counterNavigatorKey, + routes: [ + GoRoute( + name: CounterPage.name, + path: CounterPage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage(child: CounterPage()); + }, + ), + ], + ), + StatefulShellBranch( + navigatorKey: _moreNavigatorKey, + routes: [ + GoRoute( + name: MorePage.name, + path: MorePage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage( + key: ValueKey(MorePage.name), + child: MorePage(), + ); + }, + routes: [ + GoRoute( + path: ProfilePage.path, + name: ProfilePage.name, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage(child: ProfilePage()); + }, + ), + GoRoute( + name: SettingsPage.name, + path: SettingsPage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage(child: SettingsPage()); + }, + ), + ], + ), + ], + ), + ], + ); + } + + static List get commonRoutes { + return [ + GoRoute( + name: LanguagePage.name, + path: LanguagePage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage( + child: LanguagePage(), + ); + }, + ), + ]; + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart new file mode 100644 index 00000000000..88a641bcf67 --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart @@ -0,0 +1,47 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; +import 'package:go_router/go_router.dart'; + +import 'pages/pages.dart'; + +class ScaffoldShell extends StatelessWidget { + /// Create a new instance of [AppScaffoldShell] + const ScaffoldShell({ + required this.navigationShell, + super.key, + }); + + /// The navigation shell to use with the navigation. + final StatefulNavigationShell navigationShell; + + @override + Widget build(BuildContext context) { + return AdaptiveScaffold( + useDrawer: false, + body: (BuildContext context) => navigationShell, + selectedIndex: navigationShell.currentIndex, + onSelectedIndexChange: (int index) { + navigationShell.goBranch( + index, + initialLocation: index == navigationShell.currentIndex, + ); + }, + destinations: navigationShell.route.branches.map( + (StatefulShellBranch e) { + return switch (e.defaultRoute?.name) { + HomePage.name => const NavigationDestination( + icon: Icon(Icons.home), label: 'Home'), + CounterPage.name => const NavigationDestination( + icon: Icon(Icons.add), label: 'Counter'), + MorePage.name => const NavigationDestination( + icon: Icon(Icons.more), label: 'More'), + _ => throw UnimplementedError( + 'The route ${e.defaultRoute?.name} is not implemented.', + ), + }; + }, + ).toList(), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/pubspec.yaml b/packages/flutter_adaptive_scaffold/example/pubspec.yaml index f73ddc3ccbc..5ee637507c5 100644 --- a/packages/flutter_adaptive_scaffold/example/pubspec.yaml +++ b/packages/flutter_adaptive_scaffold/example/pubspec.yaml @@ -12,9 +12,10 @@ dependencies: sdk: flutter flutter_adaptive_scaffold: path: .. + go_router: ^14.2.3 dev_dependencies: - build_runner: ^2.1.10 + build_runner: ^2.4.12 flutter_test: sdk: flutter diff --git a/packages/flutter_adaptive_scaffold/lib/src/navigation_suite_scaffold.dart b/packages/flutter_adaptive_scaffold/lib/src/navigation_suite_scaffold.dart new file mode 100644 index 00000000000..aa0e1e4bb5d --- /dev/null +++ b/packages/flutter_adaptive_scaffold/lib/src/navigation_suite_scaffold.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; + +class NavigationSuiteScaffold extends Scaffold { + const NavigationSuiteScaffold({ + super.key, + super.appBar, + super.body, + super.floatingActionButton, + super.floatingActionButtonLocation, + super.floatingActionButtonAnimator, + super.persistentFooterButtons, + super.persistentFooterAlignment = AlignmentDirectional.centerEnd, + super.drawer, + super.onDrawerChanged, + super.endDrawer, + super.onEndDrawerChanged, + super.bottomNavigationBar, + super.bottomSheet, + super.backgroundColor, + super.resizeToAvoidBottomInset, + super.primary = true, + super.drawerDragStartBehavior, + super.extendBody = false, + super.extendBodyBehindAppBar = false, + super.drawerScrimColor, + super.drawerEdgeDragWidth, + super.drawerEnableOpenDragGesture = true, + super.endDrawerEnableOpenDragGesture = true, + super.restorationId, + }); +} From c1da62a53a4534bed40cff6169bc3cf3499bcac7 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Mon, 19 Aug 2024 17:10:55 +0200 Subject: [PATCH 02/19] Fix path --- .../example/lib/go_router_demo/pages/detail_modal_page.dart | 2 +- .../example/lib/go_router_demo/pages/detail_page.dart | 2 +- .../example/lib/go_router_demo/pages/forgot_password_page.dart | 2 +- .../example/lib/go_router_demo/pages/profile_page.dart | 2 +- .../example/lib/go_router_demo/pages/settings_page.dart | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart index ad069d986d4..a52d806d1e1 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; class DetailModalPage extends StatelessWidget { const DetailModalPage({Key? key}) : super(key: key); - static const String path = '/detail-modal'; + static const String path = 'detail-modal'; static const String name = 'DetailModal'; @override diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart index 565e7894e50..5546501f68e 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; class DetailPage extends StatelessWidget { const DetailPage({Key? key}) : super(key: key); - static const String path = '/detail'; + static const String path = 'detail'; static const String name = 'Detail'; @override diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart index 593c95f436e..7d8bc1e5565 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; class ForgotPasswordPage extends StatelessWidget { const ForgotPasswordPage({Key? key}) : super(key: key); - static const String path = '/forgot_password'; + static const String path = 'forgot_password'; static const String name = 'ForgotPassword'; @override diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart index 8963af332da..7d8b0294edc 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; class ProfilePage extends StatelessWidget { const ProfilePage({Key? key}) : super(key: key); - static const String path = '/profile'; + static const String path = 'profile'; static const String name = 'Profile'; @override diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart index 5115d1b3051..8de92d707a8 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; class SettingsPage extends StatelessWidget { const SettingsPage({Key? key}) : super(key: key); - static const String path = '/settings'; + static const String path = 'settings'; static const String name = 'Settings'; @override From 3abe3328a630ae16d16e56befdfd7a54279e450b Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Tue, 20 Aug 2024 14:39:36 +0200 Subject: [PATCH 03/19] Fix routes --- .../lib/go_router_demo/global_router.dart | 44 +++- .../lib/go_router_demo/pages/login_page.dart | 18 +- .../example/lib/go_router_demo/routes.dart | 244 +++++++++--------- .../lib/go_router_demo/scaffold_shell.dart | 3 +- 4 files changed, 167 insertions(+), 142 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart index 0e614d21498..f179bd79061 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart @@ -13,31 +13,47 @@ final GlobalKey rootNavigatorKey = /// Routes that are `fullScreenDialogs` should also set `_rootNavigatorKey` as /// the `parentNavigatorKey` to ensure that the dialog is displayed correctly. class GlobalRouter { + /// The authentication status of the user. + static bool authenticated = 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(child: NavigationErrorPage()); }, redirect: (BuildContext context, GoRouterState state) async { - // Check if the route we want navigate to is a shared route, so we don't - // need to check auth status. - if (Routes.commonRoutes.any( - (GoRoute e) => state.fullPath?.contains(e.path) ?? false, - )) { + // Get the path the user is trying to navigate to. + final String? path = state.fullPath; + + // If the route is part of the common routes, no auth check is required. + if (Routes.commonRoutes + .any((GoRoute e) => path?.contains(e.path) ?? false)) { return null; } - // TODO: Implement authentication status check - final bool authenticated = false; + final Iterable unauthenticatedRoutes = + RouteBase.routesRecursively(Routes.unauthenticatedRoutes.routes) + .whereType(); + final Iterable authenticatedRoutes = + RouteBase.routesRecursively(Routes.authenticatedRoutes.routes) + .whereType(); - //TODO: check unauthenticated routes - // if (!authenticated && routes.unauthenticatedRoutes.any(state.fullPath) - // return null; - // else if(!authenticated) - // return LoginPage.path; - // else if(authenticated && state.fullPath == LoginPage.path) - // return HomePage.path; + // If the user is not authenticated + if (!authenticated) { + if (unauthenticatedRoutes.any((GoRoute route) => route.path == path)) { + return null; // Allow navigation to unauthenticated routes + } else { + return LoginPage.path; // Redirect to login page + } + } else if (authenticated) { + if (authenticatedRoutes.any((GoRoute route) => route.path == path)) { + return null; // Allow navigation to authenticated routes + } else { + return HomePage.path; // Redirect to home page + } + } // In any other case the redirect can be safely ignored and handled as is. return null; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart index b8950608b4d..07d0d122d0e 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart @@ -1,4 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; + +import '../global_router.dart'; class LoginPage extends StatelessWidget { const LoginPage({Key? key}) : super(key: key); @@ -8,9 +11,20 @@ class LoginPage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Scaffold( + return Scaffold( body: Center( - child: Text('Login Page'), + child: Column( + children: [ + const Text('Login Page'), + TextButton( + onPressed: () => { + GlobalRouter.authenticated = true, + context.go('/'), + }, + child: const Text('Login'), + ), + ], + ), ), ); } diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart index 8935f7efd7d..4ca5bf38b10 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart @@ -15,134 +15,130 @@ final GlobalKey _moreNavigatorKey = /// Stores the routes that are accessible to unauthenticated users. class Routes { /// The route for the login page. - static GoRoute get unauthenticatedRoutes { - return GoRoute( - name: LoginPage.name, - path: LoginPage.path, - pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage(child: LoginPage()); - }, - routes: [ - GoRoute( - name: ForgotPasswordPage.name, - path: ForgotPasswordPage.path, - pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage( - child: ForgotPasswordPage(), - ); - }, - ), - ], - ); - } - - /// The routes for the authenticated user. - static StatefulShellRoute get authenticatedRoutes { - return StatefulShellRoute.indexedStack( - parentNavigatorKey: router.rootNavigatorKey, - builder: ( - BuildContext context, - GoRouterState state, - StatefulNavigationShell navigationShell, - ) { - return ScaffoldShell(navigationShell: navigationShell); - }, - branches: [ - StatefulShellBranch( - navigatorKey: _homeNavigatorKey, - routes: [ - GoRoute( - name: HomePage.name, - path: HomePage.path, - pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage( - child: HomePage(), - ); - }, - routes: [ - GoRoute( - name: DetailPage.name, - path: DetailPage.path, - parentNavigatorKey: router.rootNavigatorKey, - pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage( - child: DetailPage(), - ); - }, - ), - GoRoute( - name: DetailModalPage.name, - path: DetailModalPage.path, - parentNavigatorKey: router.rootNavigatorKey, - pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage( - fullscreenDialog: true, - child: DetailModalPage(), - ); - }, - ), - ], - ), - ], - ), - StatefulShellBranch( - navigatorKey: _counterNavigatorKey, - routes: [ - GoRoute( - name: CounterPage.name, - path: CounterPage.path, - pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage(child: CounterPage()); - }, - ), - ], - ), - StatefulShellBranch( - navigatorKey: _moreNavigatorKey, - routes: [ - GoRoute( - name: MorePage.name, - path: MorePage.path, - pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage( - key: ValueKey(MorePage.name), - child: MorePage(), - ); - }, - routes: [ - GoRoute( - path: ProfilePage.path, - name: ProfilePage.name, - pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage(child: ProfilePage()); - }, - ), - GoRoute( - name: SettingsPage.name, - path: SettingsPage.path, - pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage(child: SettingsPage()); - }, - ), - ], - ), - ], - ), - ], - ); - } - - static List get commonRoutes { - return [ + static final GoRoute unauthenticatedRoutes = GoRoute( + name: LoginPage.name, + path: LoginPage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage(child: LoginPage()); + }, + routes: [ GoRoute( - name: LanguagePage.name, - path: LanguagePage.path, + name: ForgotPasswordPage.name, + path: ForgotPasswordPage.path, pageBuilder: (BuildContext context, GoRouterState state) { return const MaterialPage( - child: LanguagePage(), + child: ForgotPasswordPage(), ); }, ), - ]; - } + ], + ); + + /// The routes for the authenticated user. + static final StatefulShellRoute authenticatedRoutes = + StatefulShellRoute.indexedStack( + parentNavigatorKey: router.rootNavigatorKey, + builder: ( + BuildContext context, + GoRouterState state, + StatefulNavigationShell navigationShell, + ) { + return ScaffoldShell(navigationShell: navigationShell); + }, + branches: [ + StatefulShellBranch( + navigatorKey: _homeNavigatorKey, + routes: [ + GoRoute( + name: HomePage.name, + path: HomePage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + //Maybe NoTransitionPage? + return const MaterialPage( + child: HomePage(), + ); + }, + routes: [ + GoRoute( + name: DetailPage.name, + path: DetailPage.path, + parentNavigatorKey: router.rootNavigatorKey, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage( + child: DetailPage(), + ); + }, + ), + GoRoute( + name: DetailModalPage.name, + path: DetailModalPage.path, + parentNavigatorKey: router.rootNavigatorKey, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage( + fullscreenDialog: true, + child: DetailModalPage(), + ); + }, + ), + ], + ), + ], + ), + StatefulShellBranch( + navigatorKey: _counterNavigatorKey, + routes: [ + GoRoute( + name: CounterPage.name, + path: CounterPage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage(child: CounterPage()); + }, + ), + ], + ), + StatefulShellBranch( + navigatorKey: _moreNavigatorKey, + routes: [ + GoRoute( + name: MorePage.name, + path: MorePage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage( + key: ValueKey(MorePage.name), + child: MorePage(), + ); + }, + routes: [ + GoRoute( + path: ProfilePage.path, + name: ProfilePage.name, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage(child: ProfilePage()); + }, + ), + GoRoute( + name: SettingsPage.name, + path: SettingsPage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage(child: SettingsPage()); + }, + ), + ], + ), + ], + ), + ], + ); + + static final List commonRoutes = [ + GoRoute( + name: LanguagePage.name, + path: LanguagePage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage( + child: LanguagePage(), + ); + }, + ), + ]; } diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart index 88a641bcf67..e924e42e781 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; import 'package:go_router/go_router.dart'; @@ -35,7 +34,7 @@ class ScaffoldShell extends StatelessWidget { CounterPage.name => const NavigationDestination( icon: Icon(Icons.add), label: 'Counter'), MorePage.name => const NavigationDestination( - icon: Icon(Icons.more), label: 'More'), + icon: Icon(Icons.account_circle), label: 'More'), _ => throw UnimplementedError( 'The route ${e.defaultRoute?.name} is not implemented.', ), From 42cc48625491f574ec4777883bd190778b7f4c88 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Tue, 20 Aug 2024 14:42:28 +0200 Subject: [PATCH 04/19] Delete --- .../lib/src/navigation_suite_scaffold.dart | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 packages/flutter_adaptive_scaffold/lib/src/navigation_suite_scaffold.dart diff --git a/packages/flutter_adaptive_scaffold/lib/src/navigation_suite_scaffold.dart b/packages/flutter_adaptive_scaffold/lib/src/navigation_suite_scaffold.dart deleted file mode 100644 index aa0e1e4bb5d..00000000000 --- a/packages/flutter_adaptive_scaffold/lib/src/navigation_suite_scaffold.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'package:flutter/material.dart'; - -class NavigationSuiteScaffold extends Scaffold { - const NavigationSuiteScaffold({ - super.key, - super.appBar, - super.body, - super.floatingActionButton, - super.floatingActionButtonLocation, - super.floatingActionButtonAnimator, - super.persistentFooterButtons, - super.persistentFooterAlignment = AlignmentDirectional.centerEnd, - super.drawer, - super.onDrawerChanged, - super.endDrawer, - super.onEndDrawerChanged, - super.bottomNavigationBar, - super.bottomSheet, - super.backgroundColor, - super.resizeToAvoidBottomInset, - super.primary = true, - super.drawerDragStartBehavior, - super.extendBody = false, - super.extendBodyBehindAppBar = false, - super.drawerScrimColor, - super.drawerEdgeDragWidth, - super.drawerEnableOpenDragGesture = true, - super.endDrawerEnableOpenDragGesture = true, - super.restorationId, - }); -} From 627211fb00f8a92ab96c85ef10d92fe3531426f3 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Tue, 20 Aug 2024 14:50:53 +0200 Subject: [PATCH 05/19] Depend on local --- packages/flutter_adaptive_scaffold/example/pubspec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/flutter_adaptive_scaffold/example/pubspec.yaml b/packages/flutter_adaptive_scaffold/example/pubspec.yaml index 5ee637507c5..3de1efa560f 100644 --- a/packages/flutter_adaptive_scaffold/example/pubspec.yaml +++ b/packages/flutter_adaptive_scaffold/example/pubspec.yaml @@ -12,7 +12,8 @@ dependencies: sdk: flutter flutter_adaptive_scaffold: path: .. - go_router: ^14.2.3 + go_router: + path: ../../go_router dev_dependencies: build_runner: ^2.4.12 From b7340c7496dac817110b85e670f32e0f96fca9b2 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Tue, 20 Aug 2024 16:22:37 +0200 Subject: [PATCH 06/19] Fix --- .../example/lib/go_router_demo.dart | 8 ++++++ .../lib/go_router_demo/global_router.dart | 25 +++++++++--------- .../lib/go_router_demo/pages/home_page.dart | 26 +++++++++++++++++-- .../lib/go_router_demo/pages/login_page.dart | 4 ++- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart index c84d6885fbb..2c7b99f0120 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart @@ -20,6 +20,14 @@ class MyApp extends StatelessWidget { return MaterialApp.router( restorationScopeId: 'demo', routerConfig: GlobalRouter.router, + theme: ThemeData( + colorScheme: ColorScheme.fromSeed( + seedColor: Colors.blue, + dynamicSchemeVariant: DynamicSchemeVariant.vibrant, + primary: Colors.blue, + ), + useMaterial3: true, + ), ); } } diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart index f179bd79061..54b40eff44f 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart @@ -16,6 +16,14 @@ class GlobalRouter { /// The authentication status of the user. static bool authenticated = false; + static final Iterable _unauthenticatedGoRoutes = + RouteBase.routesRecursively(Routes.unauthenticatedRoutes.routes) + .whereType(); + + static final Iterable _authenticatedGoRoutes = + RouteBase.routesRecursively(Routes.authenticatedRoutes.routes) + .whereType(); + /// The router with the routes of pages that should be displayed. static final GoRouter router = GoRouter( navigatorKey: rootNavigatorKey, @@ -25,30 +33,23 @@ class GlobalRouter { }, redirect: (BuildContext context, GoRouterState state) async { // Get the path the user is trying to navigate to. - final String? path = state.fullPath; + final String? path = state.topRoute?.path ?? state.fullPath; // If the route is part of the common routes, no auth check is required. - if (Routes.commonRoutes - .any((GoRoute e) => path?.contains(e.path) ?? false)) { + if (Routes.commonRoutes.any((GoRoute route) => route.path == path)) { return null; } - final Iterable unauthenticatedRoutes = - RouteBase.routesRecursively(Routes.unauthenticatedRoutes.routes) - .whereType(); - final Iterable authenticatedRoutes = - RouteBase.routesRecursively(Routes.authenticatedRoutes.routes) - .whereType(); - // If the user is not authenticated if (!authenticated) { - if (unauthenticatedRoutes.any((GoRoute route) => route.path == path)) { + if (_unauthenticatedGoRoutes + .any((GoRoute route) => route.path == path)) { return null; // Allow navigation to unauthenticated routes } else { return LoginPage.path; // Redirect to login page } } else if (authenticated) { - if (authenticatedRoutes.any((GoRoute route) => route.path == path)) { + if (_authenticatedGoRoutes.any((GoRoute route) => route.path == path)) { return null; // Allow navigation to authenticated routes } else { return HomePage.path; // Redirect to home page diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart index 8c6f95a4079..69d69e0b9a1 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart @@ -1,4 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; + +import 'pages.dart'; class HomePage extends StatelessWidget { const HomePage({Key? key}) : super(key: key); @@ -8,9 +11,28 @@ class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Scaffold( + return Scaffold( body: Center( - child: Text('Home Page'), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('Home Page'), + const SizedBox(height: 16), + ElevatedButton( + onPressed: () => { + context.goNamed(DetailPage.name), + }, + child: const Text('Detail page'), + ), + const SizedBox(height: 16), + ElevatedButton( + onPressed: () => { + context.goNamed(DetailModalPage.name), + }, + child: const Text('Detail modal page'), + ), + ], + ), ), ); } diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart index 07d0d122d0e..455ebe91746 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart @@ -14,9 +14,11 @@ class LoginPage extends StatelessWidget { return Scaffold( body: Center( child: Column( + mainAxisAlignment: MainAxisAlignment.center, children: [ const Text('Login Page'), - TextButton( + const SizedBox(height: 16), + ElevatedButton( onPressed: () => { GlobalRouter.authenticated = true, context.go('/'), From 2d05bb14aa8a844267651835ec0195adb35fc7e5 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Wed, 21 Aug 2024 22:51:08 +0200 Subject: [PATCH 07/19] Fixes --- .../example/lib/go_router_demo/pages/counter_page.dart | 2 +- .../example/lib/go_router_demo/pages/detail_modal_page.dart | 2 +- .../example/lib/go_router_demo/pages/detail_page.dart | 2 +- .../example/lib/go_router_demo/pages/forgot_password_page.dart | 2 +- .../example/lib/go_router_demo/pages/home_page.dart | 2 +- .../example/lib/go_router_demo/pages/language_page.dart | 2 +- .../example/lib/go_router_demo/pages/login_page.dart | 2 +- .../example/lib/go_router_demo/pages/more_page.dart | 2 +- .../example/lib/go_router_demo/pages/navigation_error_page.dart | 2 +- .../example/lib/go_router_demo/pages/profile_page.dart | 2 +- .../example/lib/go_router_demo/pages/settings_page.dart | 2 +- .../example/lib/go_router_demo/scaffold_shell.dart | 2 ++ 12 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart index 0b1ec0d5792..407cccf7582 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class CounterPage extends StatelessWidget { - const CounterPage({Key? key}) : super(key: key); + const CounterPage({super.key}); static const String path = '/counter'; static const String name = 'Counter'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart index a52d806d1e1..daf63e8693f 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class DetailModalPage extends StatelessWidget { - const DetailModalPage({Key? key}) : super(key: key); + const DetailModalPage({super.key}); static const String path = 'detail-modal'; static const String name = 'DetailModal'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart index 5546501f68e..938725519b6 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class DetailPage extends StatelessWidget { - const DetailPage({Key? key}) : super(key: key); + const DetailPage({super.key}); static const String path = 'detail'; static const String name = 'Detail'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart index 7d8bc1e5565..661af02a03a 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class ForgotPasswordPage extends StatelessWidget { - const ForgotPasswordPage({Key? key}) : super(key: key); + const ForgotPasswordPage({super.key}); static const String path = 'forgot_password'; static const String name = 'ForgotPassword'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart index 69d69e0b9a1..258b9a15349 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart @@ -4,7 +4,7 @@ import 'package:go_router/go_router.dart'; import 'pages.dart'; class HomePage extends StatelessWidget { - const HomePage({Key? key}) : super(key: key); + const HomePage({super.key}); static const String path = '/home'; static const String name = 'Home'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart index a9bef5826a2..093310c420f 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class LanguagePage extends StatelessWidget { - const LanguagePage({Key? key}) : super(key: key); + const LanguagePage({super.key}); static const String path = '/language'; static const String name = 'Language'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart index 455ebe91746..ee0424c1a2e 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart @@ -4,7 +4,7 @@ import 'package:go_router/go_router.dart'; import '../global_router.dart'; class LoginPage extends StatelessWidget { - const LoginPage({Key? key}) : super(key: key); + const LoginPage({super.key}); static const String path = '/login'; static const String name = 'Login'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart index e47393b03b8..52648ab9c88 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class MorePage extends StatelessWidget { - const MorePage({Key? key}) : super(key: key); + const MorePage({super.key}); static const String path = '/more'; static const String name = 'More'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart index 4a5c72f476e..649dcc605c3 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class NavigationErrorPage extends StatelessWidget { - const NavigationErrorPage({Key? key}) : super(key: key); + const NavigationErrorPage({super.key}); static const String path = '/error'; static const String name = 'Error'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart index 7d8b0294edc..cd628d71742 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class ProfilePage extends StatelessWidget { - const ProfilePage({Key? key}) : super(key: key); + const ProfilePage({super.key}); static const String path = 'profile'; static const String name = 'Profile'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart index 8de92d707a8..6c95e9bf9bc 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class SettingsPage extends StatelessWidget { - const SettingsPage({Key? key}) : super(key: key); + const SettingsPage({super.key}); static const String path = 'settings'; static const String name = 'Settings'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart index e924e42e781..4a5d891e36e 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart @@ -4,6 +4,8 @@ import 'package:go_router/go_router.dart'; import 'pages/pages.dart'; +/// The [ScaffoldShell] is a [StatelessWidget] that uses the [AdaptiveScaffold] +/// to create a shell for the application. class ScaffoldShell extends StatelessWidget { /// Create a new instance of [AppScaffoldShell] const ScaffoldShell({ From 797fd3259735c0c19705a92e183c63cb464103bf Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Thu, 29 Aug 2024 08:56:53 +0200 Subject: [PATCH 08/19] Fix redirect --- .../lib/go_router_demo/global_router.dart | 28 ------------------- .../example/lib/go_router_demo/routes.dart | 13 +++++++++ 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart index 54b40eff44f..ff7489114f4 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart @@ -31,34 +31,6 @@ class GlobalRouter { errorPageBuilder: (BuildContext context, GoRouterState state) { return const MaterialPage(child: NavigationErrorPage()); }, - redirect: (BuildContext context, GoRouterState state) async { - // Get the path the user is trying to navigate to. - final String? path = state.topRoute?.path ?? state.fullPath; - - // If the route is part of the common routes, no auth check is required. - if (Routes.commonRoutes.any((GoRoute route) => route.path == path)) { - return null; - } - - // If the user is not authenticated - if (!authenticated) { - if (_unauthenticatedGoRoutes - .any((GoRoute route) => route.path == path)) { - return null; // Allow navigation to unauthenticated routes - } else { - return LoginPage.path; // Redirect to login page - } - } else if (authenticated) { - if (_authenticatedGoRoutes.any((GoRoute route) => route.path == path)) { - return null; // Allow navigation to authenticated routes - } else { - return HomePage.path; // Redirect to home page - } - } - - // In any other case the redirect can be safely ignored and handled as is. - return null; - }, routes: [ Routes.unauthenticatedRoutes, Routes.authenticatedRoutes, diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart index 4ca5bf38b10..dfd838d6eee 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'global_router.dart' as router show rootNavigatorKey; +import 'global_router.dart'; import 'pages/pages.dart'; import 'scaffold_shell.dart'; @@ -21,6 +22,12 @@ class Routes { pageBuilder: (BuildContext context, GoRouterState state) { return const MaterialPage(child: LoginPage()); }, + redirect: (BuildContext context, GoRouterState state) { + if (GlobalRouter.authenticated) { + return HomePage.path; + } + return null; + }, routes: [ GoRoute( name: ForgotPasswordPage.name, @@ -45,6 +52,12 @@ class Routes { ) { return ScaffoldShell(navigationShell: navigationShell); }, + redirect: (BuildContext context, GoRouterState state) { + if (!GlobalRouter.authenticated) { + return LoginPage.path; + } + return null; + }, branches: [ StatefulShellBranch( navigatorKey: _homeNavigatorKey, From a36df7e5478677cf833fb9ceaa1e358a10d3c5ff Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Thu, 29 Aug 2024 09:26:54 +0200 Subject: [PATCH 09/19] Fixes --- .../example/lib/go_router_demo.dart | 4 +- .../{routes.dart => app_router.dart} | 49 +++++++++++++------ .../lib/go_router_demo/global_router.dart | 40 --------------- .../go_router_demo/pages/counter_page.dart | 3 ++ .../pages/detail_modal_page.dart | 3 ++ .../lib/go_router_demo/pages/detail_page.dart | 3 ++ .../pages/forgot_password_page.dart | 3 ++ .../lib/go_router_demo/pages/home_page.dart | 3 ++ .../go_router_demo/pages/language_page.dart | 3 ++ .../lib/go_router_demo/pages/login_page.dart | 7 ++- .../lib/go_router_demo/pages/more_page.dart | 3 ++ .../pages/navigation_error_page.dart | 3 ++ .../go_router_demo/pages/profile_page.dart | 3 ++ .../go_router_demo/pages/settings_page.dart | 3 ++ 14 files changed, 71 insertions(+), 59 deletions(-) rename packages/flutter_adaptive_scaffold/example/lib/go_router_demo/{routes.dart => app_router.dart} (77%) delete mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart index 2c7b99f0120..5918197d376 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; -import 'go_router_demo/global_router.dart'; +import 'go_router_demo/app_router.dart'; void main() { runApp(const MyApp()); @@ -19,7 +19,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp.router( restorationScopeId: 'demo', - routerConfig: GlobalRouter.router, + routerConfig: AppRouter.router, theme: ThemeData( colorScheme: ColorScheme.fromSeed( seedColor: Colors.blue, diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart similarity index 77% rename from packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart rename to packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart index dfd838d6eee..c9114cfdf34 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/routes.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart @@ -1,11 +1,12 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; -import 'global_router.dart' as router show rootNavigatorKey; - -import 'global_router.dart'; import 'pages/pages.dart'; import 'scaffold_shell.dart'; +/// The root navigator key for the main router of the app. +final GlobalKey rootNavigatorKey = + GlobalKey(debugLabel: 'root'); + final GlobalKey _homeNavigatorKey = GlobalKey(debugLabel: 'home'); final GlobalKey _counterNavigatorKey = @@ -13,17 +14,36 @@ final GlobalKey _counterNavigatorKey = final GlobalKey _moreNavigatorKey = GlobalKey(debugLabel: 'more'); -/// Stores the routes that are accessible to unauthenticated users. -class Routes { - /// The route for the login page. - static final GoRoute unauthenticatedRoutes = GoRoute( +/// 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 bool authenticated = 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(child: NavigationErrorPage()); + }, + routes: [ + _unauthenticatedRoutes, + _authenticatedRoutes, + ..._openRoutes, + ], + ); + + static final GoRoute _unauthenticatedRoutes = GoRoute( name: LoginPage.name, path: LoginPage.path, pageBuilder: (BuildContext context, GoRouterState state) { return const MaterialPage(child: LoginPage()); }, redirect: (BuildContext context, GoRouterState state) { - if (GlobalRouter.authenticated) { + if (authenticated) { return HomePage.path; } return null; @@ -41,10 +61,9 @@ class Routes { ], ); - /// The routes for the authenticated user. - static final StatefulShellRoute authenticatedRoutes = + static final StatefulShellRoute _authenticatedRoutes = StatefulShellRoute.indexedStack( - parentNavigatorKey: router.rootNavigatorKey, + parentNavigatorKey: rootNavigatorKey, builder: ( BuildContext context, GoRouterState state, @@ -53,7 +72,7 @@ class Routes { return ScaffoldShell(navigationShell: navigationShell); }, redirect: (BuildContext context, GoRouterState state) { - if (!GlobalRouter.authenticated) { + if (!authenticated) { return LoginPage.path; } return null; @@ -75,7 +94,7 @@ class Routes { GoRoute( name: DetailPage.name, path: DetailPage.path, - parentNavigatorKey: router.rootNavigatorKey, + parentNavigatorKey: rootNavigatorKey, pageBuilder: (BuildContext context, GoRouterState state) { return const MaterialPage( child: DetailPage(), @@ -85,7 +104,7 @@ class Routes { GoRoute( name: DetailModalPage.name, path: DetailModalPage.path, - parentNavigatorKey: router.rootNavigatorKey, + parentNavigatorKey: rootNavigatorKey, pageBuilder: (BuildContext context, GoRouterState state) { return const MaterialPage( fullscreenDialog: true, @@ -143,7 +162,7 @@ class Routes { ], ); - static final List commonRoutes = [ + static final List _openRoutes = [ GoRoute( name: LanguagePage.name, path: LanguagePage.path, diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart deleted file mode 100644 index ff7489114f4..00000000000 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/global_router.dart +++ /dev/null @@ -1,40 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:go_router/go_router.dart'; - -import 'pages/pages.dart'; -import 'routes.dart'; - -/// The root navigator key for the main router of the app. -final GlobalKey rootNavigatorKey = - GlobalKey(debugLabel: 'root'); - -/// The [GlobalRouter] 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 GlobalRouter { - /// The authentication status of the user. - static bool authenticated = false; - - static final Iterable _unauthenticatedGoRoutes = - RouteBase.routesRecursively(Routes.unauthenticatedRoutes.routes) - .whereType(); - - static final Iterable _authenticatedGoRoutes = - RouteBase.routesRecursively(Routes.authenticatedRoutes.routes) - .whereType(); - - /// 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(child: NavigationErrorPage()); - }, - routes: [ - Routes.unauthenticatedRoutes, - Routes.authenticatedRoutes, - ...Routes.commonRoutes, - ], - ); -} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart index 407cccf7582..8185cd72ac7 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart @@ -3,7 +3,10 @@ import 'package:flutter/material.dart'; class CounterPage extends StatelessWidget { 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 diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart index daf63e8693f..fc820d031ae 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart @@ -3,7 +3,10 @@ import 'package:flutter/material.dart'; class DetailModalPage extends StatelessWidget { 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 diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart index 938725519b6..c529a6a31d6 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart @@ -3,7 +3,10 @@ import 'package:flutter/material.dart'; class DetailPage extends StatelessWidget { const DetailPage({super.key}); + /// The path for the detail page. static const String path = 'detail'; + + /// The name for the detail page. static const String name = 'Detail'; @override diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart index 661af02a03a..f8c33dbf550 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart @@ -3,7 +3,10 @@ import 'package:flutter/material.dart'; class ForgotPasswordPage extends StatelessWidget { 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 diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart index 258b9a15349..697279953ae 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart @@ -6,7 +6,10 @@ import 'pages.dart'; class HomePage extends StatelessWidget { const HomePage({super.key}); + /// The path for the home page. static const String path = '/home'; + + /// The name for the home page. static const String name = 'Home'; @override diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart index 093310c420f..1faa475feab 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart @@ -3,7 +3,10 @@ import 'package:flutter/material.dart'; class LanguagePage extends StatelessWidget { const LanguagePage({super.key}); + /// The path for the language page. static const String path = '/language'; + + /// The name for the language page. static const String name = 'Language'; @override diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart index ee0424c1a2e..8e2538324f6 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart @@ -1,12 +1,15 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; -import '../global_router.dart'; +import '../app_router.dart'; class LoginPage extends StatelessWidget { const LoginPage({super.key}); + /// The path for the login page. static const String path = '/login'; + + /// The name for the login page. static const String name = 'Login'; @override @@ -20,7 +23,7 @@ class LoginPage extends StatelessWidget { const SizedBox(height: 16), ElevatedButton( onPressed: () => { - GlobalRouter.authenticated = true, + AppRouter.authenticated = true, context.go('/'), }, child: const Text('Login'), diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart index 52648ab9c88..a2c26495d60 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart @@ -3,7 +3,10 @@ import 'package:flutter/material.dart'; class MorePage extends StatelessWidget { const MorePage({super.key}); + /// The path for the more page. static const String path = '/more'; + + /// The name for the more page. static const String name = 'More'; @override diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart index 649dcc605c3..d5044440c2a 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart @@ -3,7 +3,10 @@ import 'package:flutter/material.dart'; class NavigationErrorPage extends StatelessWidget { const NavigationErrorPage({super.key}); + /// The path for the error page. static const String path = '/error'; + + /// The name for the error page. static const String name = 'Error'; @override diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart index cd628d71742..a86bc5de579 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart @@ -3,7 +3,10 @@ import 'package:flutter/material.dart'; class ProfilePage extends StatelessWidget { const ProfilePage({super.key}); + /// The path for the profile page. static const String path = 'profile'; + + /// The name for the profile page. static const String name = 'Profile'; @override diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart index 6c95e9bf9bc..cb826869cf4 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart @@ -3,7 +3,10 @@ import 'package:flutter/material.dart'; class SettingsPage extends StatelessWidget { const SettingsPage({super.key}); + /// The path for the settings page. static const String path = 'settings'; + + /// The name for the settings page. static const String name = 'Settings'; @override From 2cd8becacc061d6eca11d7de18a3c9a3fe64b45d Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Thu, 29 Aug 2024 14:34:43 +0200 Subject: [PATCH 10/19] Fixes --- .../lib/go_router_demo/app_router.dart | 21 ++++++++++++------ .../pages/detail_modal_page.dart | 7 ++++-- .../lib/go_router_demo/pages/detail_page.dart | 7 ++++-- .../lib/go_router_demo/pages/home_page.dart | 8 ++++--- .../lib/go_router_demo/pages/login_page.dart | 4 +--- .../lib/go_router_demo/pages/more_page.dart | 22 +++++++++++++++++-- 6 files changed, 50 insertions(+), 19 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart index c9114cfdf34..c56434cfd2a 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; + import 'pages/pages.dart'; import 'scaffold_shell.dart'; @@ -20,7 +21,7 @@ final GlobalKey _moreNavigatorKey = /// the `parentNavigatorKey` to ensure that the dialog is displayed correctly. class AppRouter { /// The authentication status of the user. - static bool authenticated = false; + static ValueNotifier authenticatedNotifier = ValueNotifier(false); /// The router with the routes of pages that should be displayed. static final GoRouter router = GoRouter( @@ -29,6 +30,13 @@ class AppRouter { errorPageBuilder: (BuildContext context, GoRouterState state) { return const MaterialPage(child: NavigationErrorPage()); }, + redirect: (BuildContext context, GoRouterState state) { + if (state.matchedLocation == '/') { + return HomePage.path; + } + return null; + }, + refreshListenable: authenticatedNotifier, routes: [ _unauthenticatedRoutes, _authenticatedRoutes, @@ -43,7 +51,7 @@ class AppRouter { return const MaterialPage(child: LoginPage()); }, redirect: (BuildContext context, GoRouterState state) { - if (authenticated) { + if (authenticatedNotifier.value) { return HomePage.path; } return null; @@ -72,7 +80,7 @@ class AppRouter { return ScaffoldShell(navigationShell: navigationShell); }, redirect: (BuildContext context, GoRouterState state) { - if (!authenticated) { + if (!authenticatedNotifier.value) { return LoginPage.path; } return null; @@ -85,8 +93,7 @@ class AppRouter { name: HomePage.name, path: HomePage.path, pageBuilder: (BuildContext context, GoRouterState state) { - //Maybe NoTransitionPage? - return const MaterialPage( + return const NoTransitionPage( child: HomePage(), ); }, @@ -123,7 +130,7 @@ class AppRouter { name: CounterPage.name, path: CounterPage.path, pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage(child: CounterPage()); + return const NoTransitionPage(child: CounterPage()); }, ), ], @@ -135,7 +142,7 @@ class AppRouter { name: MorePage.name, path: MorePage.path, pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage( + return const NoTransitionPage( key: ValueKey(MorePage.name), child: MorePage(), ); diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart index fc820d031ae..feb2d78f629 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart @@ -11,8 +11,11 @@ class DetailModalPage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Scaffold( - body: Center( + return Scaffold( + appBar: AppBar( + title: const Text('Detail Modal Page'), + ), + body: const Center( child: Text('Detail modal Page'), ), ); diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart index c529a6a31d6..1c271d9d1b1 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart @@ -11,8 +11,11 @@ class DetailPage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Scaffold( - body: Center( + return Scaffold( + appBar: AppBar( + title: const Text('Detail Page'), + ), + body: const Center( child: Text('Detail Page'), ), ); diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart index 697279953ae..d79fbf855ca 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; import 'package:go_router/go_router.dart'; import 'pages.dart'; @@ -15,19 +16,20 @@ class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( + appBar: AppBar( + title: const Text('Home Page'), + ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text('Home Page'), - const SizedBox(height: 16), ElevatedButton( onPressed: () => { context.goNamed(DetailPage.name), }, child: const Text('Detail page'), ), - const SizedBox(height: 16), + const SizedBox(height: kMaterialGutterValue), ElevatedButton( onPressed: () => { context.goNamed(DetailModalPage.name), diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart index 8e2538324f6..426640a1a59 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:go_router/go_router.dart'; import '../app_router.dart'; @@ -23,8 +22,7 @@ class LoginPage extends StatelessWidget { const SizedBox(height: 16), ElevatedButton( onPressed: () => { - AppRouter.authenticated = true, - context.go('/'), + AppRouter.authenticatedNotifier.value = true, }, child: const Text('Login'), ), diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart index a2c26495d60..a15b3f5025b 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart @@ -1,4 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; +import 'package:go_router/go_router.dart'; + +import 'pages.dart'; class MorePage extends StatelessWidget { const MorePage({super.key}); @@ -11,9 +15,23 @@ class MorePage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Scaffold( + return Scaffold( body: Center( - child: Text('More Page'), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('More Page'), + ElevatedButton( + onPressed: () => context.goNamed(ProfilePage.name), + child: const Text('Profile'), + ), + const SizedBox(height: kMaterialGutterValue), + ElevatedButton( + onPressed: () => context.goNamed(SettingsPage.name), + child: const Text('Settings'), + ), + ], + ), ), ); } From 894c7f2a1365cab7e58fc47bff83d8659480e652 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Thu, 29 Aug 2024 15:07:07 +0200 Subject: [PATCH 11/19] Fix passing of parameter --- .../lib/go_router_demo/app_router.dart | 28 +++++++++---- .../pages/detail_overview_page.dart | 41 +++++++++++++++++++ .../lib/go_router_demo/pages/detail_page.dart | 9 ++-- .../lib/go_router_demo/pages/home_page.dart | 2 +- .../lib/go_router_demo/pages/pages.dart | 1 + 5 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart index c56434cfd2a..6dcfcade72e 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart @@ -99,15 +99,25 @@ class AppRouter { }, routes: [ GoRoute( - name: DetailPage.name, - path: DetailPage.path, - parentNavigatorKey: rootNavigatorKey, - pageBuilder: (BuildContext context, GoRouterState state) { - return const MaterialPage( - child: DetailPage(), - ); - }, - ), + name: DetailOverviewPage.name, + path: DetailOverviewPage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return const MaterialPage( + child: DetailOverviewPage(), + ); + }, + routes: [ + GoRoute( + name: DetailPage.name, + path: DetailPage.path, + pageBuilder: (BuildContext context, GoRouterState state) { + return MaterialPage( + child: DetailPage( + itemName: state.uri.queryParameters['itemName']!), + ); + }, + ), + ]), GoRoute( name: DetailModalPage.name, path: DetailModalPage.path, diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart new file mode 100644 index 00000000000..91361fd763b --- /dev/null +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; + +import 'detail_page.dart'; + +class DetailOverviewPage extends StatelessWidget { + 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( + children: [ + ListTile( + title: const Text('Detail Page 1'), + onTap: () => { + context.goNamed(DetailPage.name, + queryParameters: {'itemName': '1'}), + }, + ), + ListTile( + title: const Text('Detail Page 2'), + onTap: () => { + context.goNamed(DetailPage.name, + queryParameters: {'itemName': '2'}), + }, + ), + ], + ), + ); + } +} diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart index 1c271d9d1b1..570853592b4 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class DetailPage extends StatelessWidget { - const DetailPage({super.key}); + const DetailPage({super.key, required this.itemName}); /// The path for the detail page. static const String path = 'detail'; @@ -9,14 +9,17 @@ class DetailPage extends StatelessWidget { /// 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: const Center( - child: Text('Detail Page'), + body: Center( + child: Text('Detail Page: $itemName'), ), ); } diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart index d79fbf855ca..a7915f41759 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart @@ -25,7 +25,7 @@ class HomePage extends StatelessWidget { children: [ ElevatedButton( onPressed: () => { - context.goNamed(DetailPage.name), + context.goNamed(DetailOverviewPage.name), }, child: const Text('Detail page'), ), diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart index 55cf96ddfa2..3354f38198f 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart @@ -1,5 +1,6 @@ export 'counter_page.dart'; export 'detail_modal_page.dart'; +export 'detail_overview_page.dart'; export 'detail_page.dart'; export 'forgot_password_page.dart'; export 'home_page.dart'; From 83ba47c0cbe67a2c066a484dbb9ce22e14cacd0a Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Thu, 29 Aug 2024 15:13:29 +0200 Subject: [PATCH 12/19] Fixes --- .../go_router_demo/pages/counter_page.dart | 7 +++-- .../pages/detail_overview_page.dart | 28 ++++++++----------- .../pages/forgot_password_page.dart | 7 +++-- .../go_router_demo/pages/language_page.dart | 7 +++-- .../lib/go_router_demo/pages/more_page.dart | 4 ++- .../go_router_demo/pages/profile_page.dart | 19 +++++++++++-- .../go_router_demo/pages/settings_page.dart | 7 +++-- 7 files changed, 52 insertions(+), 27 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart index 8185cd72ac7..c0f09f5c81c 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart @@ -11,8 +11,11 @@ class CounterPage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Scaffold( - body: Center( + return Scaffold( + appBar: AppBar( + title: const Text('Counter Page'), + ), + body: const Center( child: Text('Counter Page'), ), ); diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart index 91361fd763b..40c6bd63609 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart @@ -18,23 +18,19 @@ class DetailOverviewPage extends StatelessWidget { appBar: AppBar( title: const Text('Detail Overview Page'), ), - body: ListView( - children: [ - ListTile( - title: const Text('Detail Page 1'), - onTap: () => { - context.goNamed(DetailPage.name, - queryParameters: {'itemName': '1'}), + body: ListView.builder( + itemCount: 10, + itemBuilder: (BuildContext context, int index) { + return ListTile( + title: Text('Item $index'), + onTap: () { + context.goNamed( + DetailPage.name, + queryParameters: {'itemName': '$index'}, + ); }, - ), - ListTile( - title: const Text('Detail Page 2'), - onTap: () => { - context.goNamed(DetailPage.name, - queryParameters: {'itemName': '2'}), - }, - ), - ], + ); + }, ), ); } diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart index f8c33dbf550..c3f5bea7de9 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart @@ -11,8 +11,11 @@ class ForgotPasswordPage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Scaffold( - body: Center( + return Scaffold( + appBar: AppBar( + title: const Text('Forgot Password'), + ), + body: const Center( child: Text('ForgotPassword Page'), ), ); diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart index 1faa475feab..85d51cc0a8b 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart @@ -11,8 +11,11 @@ class LanguagePage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Scaffold( - body: Center( + return Scaffold( + appBar: AppBar( + title: const Text('Language'), + ), + body: const Center( child: Text('Language Page'), ), ); diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart index a15b3f5025b..297ef485090 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart @@ -16,11 +16,13 @@ class MorePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( + appBar: AppBar( + title: const Text('More Page'), + ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text('More Page'), ElevatedButton( onPressed: () => context.goNamed(ProfilePage.name), child: const Text('Profile'), diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart index a86bc5de579..8dfcd4507d3 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +import '../app_router.dart'; + class ProfilePage extends StatelessWidget { const ProfilePage({super.key}); @@ -11,9 +13,22 @@ class ProfilePage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Scaffold( + return Scaffold( + appBar: AppBar( + title: const Text('Profile Page'), + ), body: Center( - child: Text('Profile Page'), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ElevatedButton( + onPressed: () => { + AppRouter.authenticatedNotifier.value = false, + }, + child: const Text('Sign Out'), + ), + ], + ), ), ); } diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart index cb826869cf4..b256795a259 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart @@ -11,8 +11,11 @@ class SettingsPage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Scaffold( - body: Center( + return Scaffold( + appBar: AppBar( + title: const Text('Settings Page'), + ), + body: const Center( child: Text('Settings Page'), ), ); From 7161e617638a0a9256570c4e1382d5e884488b0a Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Fri, 30 Aug 2024 10:44:18 +0200 Subject: [PATCH 13/19] Fix --- .../example/lib/go_router_demo/pages/home_page.dart | 2 +- .../example/lib/go_router_demo/pages/more_page.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart index a7915f41759..8e24ebb897d 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart @@ -29,7 +29,7 @@ class HomePage extends StatelessWidget { }, child: const Text('Detail page'), ), - const SizedBox(height: kMaterialGutterValue), + const SizedBox(height: kMaterialMediumAndUpMargin), ElevatedButton( onPressed: () => { context.goNamed(DetailModalPage.name), diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart index 297ef485090..4a32046cb1f 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart @@ -27,7 +27,7 @@ class MorePage extends StatelessWidget { onPressed: () => context.goNamed(ProfilePage.name), child: const Text('Profile'), ), - const SizedBox(height: kMaterialGutterValue), + const SizedBox(height: kMaterialMediumAndUpMargin), ElevatedButton( onPressed: () => context.goNamed(SettingsPage.name), child: const Text('Settings'), From 47262a5554c56c4e976c02c2930475540a534b67 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Fri, 30 Aug 2024 19:01:02 +0200 Subject: [PATCH 14/19] Docs --- .../example/lib/go_router_demo/pages/counter_page.dart | 2 ++ .../example/lib/go_router_demo/pages/detail_modal_page.dart | 2 ++ .../example/lib/go_router_demo/pages/detail_overview_page.dart | 2 ++ .../example/lib/go_router_demo/pages/detail_page.dart | 2 ++ .../example/lib/go_router_demo/pages/forgot_password_page.dart | 2 ++ .../example/lib/go_router_demo/pages/home_page.dart | 2 ++ .../example/lib/go_router_demo/pages/language_page.dart | 2 ++ .../example/lib/go_router_demo/pages/login_page.dart | 2 ++ .../example/lib/go_router_demo/pages/more_page.dart | 2 ++ .../example/lib/go_router_demo/pages/navigation_error_page.dart | 2 ++ .../example/lib/go_router_demo/pages/profile_page.dart | 2 ++ .../example/lib/go_router_demo/pages/settings_page.dart | 2 ++ 12 files changed, 24 insertions(+) diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart index c0f09f5c81c..74d9d296491 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart @@ -1,6 +1,8 @@ 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. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart index feb2d78f629..56a6de2681b 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart @@ -1,6 +1,8 @@ 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. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart index 40c6bd63609..f63105ae169 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart @@ -3,7 +3,9 @@ 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. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart index 570853592b4..ef923e3b7c1 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart @@ -1,6 +1,8 @@ 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. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart index c3f5bea7de9..e21924dca54 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart @@ -1,6 +1,8 @@ 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. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart index 8e24ebb897d..dfe61009ecc 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart @@ -4,7 +4,9 @@ import 'package:go_router/go_router.dart'; import 'pages.dart'; +/// The home page. class HomePage extends StatelessWidget { + /// Construct the home page. const HomePage({super.key}); /// The path for the home page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart index 85d51cc0a8b..3c6f43ca774 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; +/// The language page. class LanguagePage extends StatelessWidget { + /// Construct the language page. const LanguagePage({super.key}); /// The path for the language page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart index 426640a1a59..3c732a1728f 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart @@ -2,7 +2,9 @@ import 'package:flutter/material.dart'; import '../app_router.dart'; +/// The login page. class LoginPage extends StatelessWidget { + /// Construct the login page. const LoginPage({super.key}); /// The path for the login page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart index 4a32046cb1f..2f113aeb484 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart @@ -4,7 +4,9 @@ import 'package:go_router/go_router.dart'; import 'pages.dart'; +/// The more page. class MorePage extends StatelessWidget { + /// Construct the more page. const MorePage({super.key}); /// The path for the more page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart index d5044440c2a..f6f82f6e421 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; +/// The error page for navigation errors. class NavigationErrorPage extends StatelessWidget { + /// Creates a new instance of the [NavigationErrorPage]. const NavigationErrorPage({super.key}); /// The path for the error page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart index 8dfcd4507d3..7abe4f6df92 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart @@ -2,7 +2,9 @@ import 'package:flutter/material.dart'; import '../app_router.dart'; +/// The profile page. class ProfilePage extends StatelessWidget { + /// Construct the profile page. const ProfilePage({super.key}); /// The path for the profile page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart index b256795a259..d6f125d3515 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; +/// The settings page. class SettingsPage extends StatelessWidget { + /// Construct the settings page. const SettingsPage({super.key}); /// The path for the settings page. From b259d3d60311e9cbcc7b55c0b0de87135f7bb4e2 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Tue, 3 Sep 2024 23:05:32 +0200 Subject: [PATCH 15/19] Pin version --- packages/flutter_adaptive_scaffold/example/pubspec.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/example/pubspec.yaml b/packages/flutter_adaptive_scaffold/example/pubspec.yaml index 3de1efa560f..3f82e2ca20e 100644 --- a/packages/flutter_adaptive_scaffold/example/pubspec.yaml +++ b/packages/flutter_adaptive_scaffold/example/pubspec.yaml @@ -12,8 +12,7 @@ dependencies: sdk: flutter flutter_adaptive_scaffold: path: .. - go_router: - path: ../../go_router + go_router: ^14.2.7 dev_dependencies: build_runner: ^2.4.12 From 43a39fe6bacf84aac944d263cb1e5ade103d9b40 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Tue, 3 Sep 2024 23:12:05 +0200 Subject: [PATCH 16/19] Update packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com> --- .../example/lib/go_router_demo/app_router.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart index 6dcfcade72e..9176e90312e 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart @@ -31,7 +31,7 @@ class AppRouter { return const MaterialPage(child: NavigationErrorPage()); }, redirect: (BuildContext context, GoRouterState state) { - if (state.matchedLocation == '/') { + if (state.uri.path == '/') { return HomePage.path; } return null; From 28480287b4fa25161c2864df06417f616ad8587c Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Wed, 4 Sep 2024 11:16:35 +0200 Subject: [PATCH 17/19] License --- .../example/lib/go_router_demo/app_router.dart | 4 ++++ .../example/lib/go_router_demo/pages/counter_page.dart | 4 ++++ .../example/lib/go_router_demo/pages/detail_modal_page.dart | 4 ++++ .../lib/go_router_demo/pages/detail_overview_page.dart | 4 ++++ .../example/lib/go_router_demo/pages/detail_page.dart | 4 ++++ .../lib/go_router_demo/pages/forgot_password_page.dart | 4 ++++ .../example/lib/go_router_demo/pages/home_page.dart | 4 ++++ .../example/lib/go_router_demo/pages/language_page.dart | 4 ++++ .../example/lib/go_router_demo/pages/login_page.dart | 4 ++++ .../example/lib/go_router_demo/pages/more_page.dart | 4 ++++ .../lib/go_router_demo/pages/navigation_error_page.dart | 4 ++++ .../example/lib/go_router_demo/pages/pages.dart | 4 ++++ .../example/lib/go_router_demo/pages/profile_page.dart | 4 ++++ .../example/lib/go_router_demo/pages/settings_page.dart | 4 ++++ .../example/lib/go_router_demo/scaffold_shell.dart | 4 ++++ 15 files changed, 60 insertions(+) diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart index 9176e90312e..ddb36662370 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/app_router.dart @@ -1,3 +1,7 @@ +// 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'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart index 74d9d296491..59b5400a145 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/counter_page.dart @@ -1,3 +1,7 @@ +// 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'; /// The counter page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart index 56a6de2681b..6ce2d75a64b 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_modal_page.dart @@ -1,3 +1,7 @@ +// 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'; /// The detail modal page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart index f63105ae169..941338e4f12 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_overview_page.dart @@ -1,3 +1,7 @@ +// 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'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart index ef923e3b7c1..0abc77f0ee6 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/detail_page.dart @@ -1,3 +1,7 @@ +// 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'; /// The detail page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart index e21924dca54..a680f5c55b2 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/forgot_password_page.dart @@ -1,3 +1,7 @@ +// 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'; /// The forgot password page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart index dfe61009ecc..05dbbad56f6 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/home_page.dart @@ -1,3 +1,7 @@ +// 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:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; import 'package:go_router/go_router.dart'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart index 3c6f43ca774..ee160726199 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/language_page.dart @@ -1,3 +1,7 @@ +// 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'; /// The language page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart index 3c732a1728f..32084550c61 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/login_page.dart @@ -1,3 +1,7 @@ +// 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 '../app_router.dart'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart index 2f113aeb484..3eca08c7f2a 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/more_page.dart @@ -1,3 +1,7 @@ +// 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:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; import 'package:go_router/go_router.dart'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart index f6f82f6e421..c50a61e6ac9 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/navigation_error_page.dart @@ -1,3 +1,7 @@ +// 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'; /// The error page for navigation errors. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart index 3354f38198f..e7d498f9652 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/pages.dart @@ -1,3 +1,7 @@ +// 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. + export 'counter_page.dart'; export 'detail_modal_page.dart'; export 'detail_overview_page.dart'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart index 7abe4f6df92..a5d2ee69e69 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/profile_page.dart @@ -1,3 +1,7 @@ +// 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 '../app_router.dart'; diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart index d6f125d3515..8357e3cdebd 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/pages/settings_page.dart @@ -1,3 +1,7 @@ +// 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'; /// The settings page. diff --git a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart index 4a5d891e36e..aa070a82c4a 100644 --- a/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart +++ b/packages/flutter_adaptive_scaffold/example/lib/go_router_demo/scaffold_shell.dart @@ -1,3 +1,7 @@ +// 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:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; import 'package:go_router/go_router.dart'; From 923f3c74f872a9229877f68486e163f089e36554 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Wed, 4 Sep 2024 11:19:02 +0200 Subject: [PATCH 18/19] Readme --- packages/flutter_adaptive_scaffold/example/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/flutter_adaptive_scaffold/example/README.md b/packages/flutter_adaptive_scaffold/example/README.md index 035288f0155..a0ab2f7aad5 100644 --- a/packages/flutter_adaptive_scaffold/example/README.md +++ b/packages/flutter_adaptive_scaffold/example/README.md @@ -1,4 +1,5 @@ # Examples + There are several examples listed in this directory: You can run the following commands in the example directory to see the appropriate demos: @@ -7,3 +8,5 @@ You can run the following commands in the example directory to see the appropria `flutter run lib/adaptive_layout_demo.dart` to see a simple usage of AdaptiveLayout. `flutter run lib/adaptive_scaffold_demo.dart` to see a simple usage of AdaptiveScaffold. + +`flutter run lib/go_router_demo.dart` to see usage of AdaptiveScaffold with GoRouter and some advanced scenarios like auth handling and branches. From e09706b5e07b4f994eee603ff117a40793c736be Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Wed, 4 Sep 2024 11:20:24 +0200 Subject: [PATCH 19/19] Changelog --- packages/flutter_adaptive_scaffold/CHANGELOG.md | 4 ++++ packages/flutter_adaptive_scaffold/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/flutter_adaptive_scaffold/CHANGELOG.md b/packages/flutter_adaptive_scaffold/CHANGELOG.md index 83d3716b01e..6f01cc38d40 100644 --- a/packages/flutter_adaptive_scaffold/CHANGELOG.md +++ b/packages/flutter_adaptive_scaffold/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.6 + +* Add new sample for using AdaptiveScaffold with GoRouter. + ## 0.2.5 * Fix breakpoint not being active in certain cases like foldables. diff --git a/packages/flutter_adaptive_scaffold/pubspec.yaml b/packages/flutter_adaptive_scaffold/pubspec.yaml index 64979c63aa5..6c9eab68f69 100644 --- a/packages/flutter_adaptive_scaffold/pubspec.yaml +++ b/packages/flutter_adaptive_scaffold/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_adaptive_scaffold description: Widgets to easily build adaptive layouts, including navigation elements. -version: 0.2.5 +version: 0.2.6 issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_adaptive_scaffold%22 repository: https://github.com/flutter/packages/tree/main/packages/flutter_adaptive_scaffold