// Copyright (C) 2023 WYATT GROUP // Please see the AUTHORS file for details. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:wyatt_go_router/wyatt_go_router.dart'; import 'package:wyatt_go_router_example/bottom_bar.dart'; import 'package:wyatt_go_router_example/page_a.dart'; import 'package:wyatt_go_router_example/page_b.dart'; import 'package:wyatt_go_router_example/page_c.dart'; abstract class AppRouter { /// Default transition for all pages static Page defaultTransition( BuildContext context, GoRouterState state, Widget child, ) => CupertinoPage(key: state.pageKey, child: child); /// Disable transition animation static Page noTransition( BuildContext context, GoRouterState state, Widget child, ) => NoTransitionPage(key: state.pageKey, child: child); static final GlobalKey rootNavigatorKey = GlobalKey(); static final GlobalKey shellNavigatorKey = GlobalKey(); /// Defines GoRoute routes. static final List routes = [ ShellRoute( navigatorKey: shellNavigatorKey, builder: (context, state, child) { final currentRoute = context.currentRoute; return Scaffold( appBar: AppBar( title: Text( currentRoute.name ?? 'Unknown', ), ), body: child, bottomNavigationBar: BottomBar( currentRoute: currentRoute, ), ); }, routes: [ GoRoute( path: '/page-a', name: 'A', pageBuilder: (context, state) => noTransition( context, state, const PageA(), ), ), GoRoute( path: '/page-b', name: 'B', pageBuilder: (context, state) => noTransition( context, state, const PageB(), ), ), ], ), GoRoute( path: '/page-c', name: 'C', parentNavigatorKey: rootNavigatorKey, pageBuilder: (context, state) => defaultTransition( context, state, const PageC(), ), ), ]; static GoRouter? _router; /// Returns the router. static GoRouter routerOf(BuildContext context) => _router ??= GoRouter( initialLocation: '/page-a', routes: AppRouter.routes, navigatorKey: rootNavigatorKey, debugLogDiagnostics: true, ); }