diff --git a/lib/presentation/core/routes/router.dart b/lib/presentation/core/routes/router.dart index 13c639f3..fa6e0a0e 100644 --- a/lib/presentation/core/routes/router.dart +++ b/lib/presentation/core/routes/router.dart @@ -64,12 +64,10 @@ class AppRouter { builder: (BuildContext context, GoRouterState state) { final extra = state.extra as Map? ?? {}; final crowdAction = extra['crowdAction'] as CrowdAction?; - final viewOnly = extra['viewOnly'] as bool? ?? false; return CrowdActionDetailsPage( crowdAction: crowdAction, crowdActionId: crowdAction?.id, - viewOnly: viewOnly, ); }, ), diff --git a/lib/presentation/home/home_screen.dart b/lib/presentation/home/home_screen.dart index 7bba7d11..c4b47a7c 100644 --- a/lib/presentation/home/home_screen.dart +++ b/lib/presentation/home/home_screen.dart @@ -1,80 +1,24 @@ -import 'package:auto_route/auto_route.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; -import '../../../presentation/themes/constants.dart'; -import '../../domain/core/i_settings_repository.dart'; -import '../../infrastructure/core/injection.dart'; import '../core/collaction_icons.dart'; -import '../routes/app_routes.gr.dart'; +import '../core/routes/app_page.dart'; +import '../themes/constants.dart'; -class HomePage extends StatefulWidget { - const HomePage({super.key}); +part 'widgets/home_nav.dart'; - @override - _HomePageState createState() => _HomePageState(); -} +class HomePage extends StatelessWidget { + // Current display page + final Widget child; -class _HomePageState extends State { - @override - void initState() { - super.initState(); - WidgetsBinding.instance.addPostFrameCallback((_) { - checkAndMaybeShowOnboarding(); - }); - } + const HomePage({super.key, required this.child}); @override Widget build(BuildContext context) { - return AutoTabsScaffold( - routes: const [ - CrowdactionRouter(), - UserProfileRouter(), - if (!kReleaseMode) ...[ - DemoScreenRouter(), - ], - ], - bottomNavigationBuilder: (_, tabsRouter) => bottomNavbar(tabsRouter), - ); - } - - Future checkAndMaybeShowOnboarding() async { - // Push onboarding screen if first time launching application - final settingsRepository = getIt(); - if (!(await settingsRepository.getWasUserOnboarded())) { - context.router.push(const OnboardingRoute()); - } - } - - Widget bottomNavbar(TabsRouter tabsRouter) { - return BottomNavigationBar( - backgroundColor: Colors.white, - showSelectedLabels: false, - showUnselectedLabels: false, - selectedItemColor: kEnabledButtonColor, - unselectedItemColor: kDisabledButtonColor, - type: BottomNavigationBarType.fixed, - elevation: 0, - items: const [ - BottomNavigationBarItem( - icon: Icon(CollactionIcons.collaction), - label: '', - ), - BottomNavigationBarItem( - icon: Icon(CollactionIcons.user), - label: '', - ), - if (!kReleaseMode) ...[ - BottomNavigationBarItem( - icon: Icon( - Icons.assignment_outlined, - ), - label: '', - ), - ], - ], - currentIndex: tabsRouter.activeIndex, - onTap: tabsRouter.setActiveIndex, + return Scaffold( + body: child, + bottomNavigationBar: bottomNavbar(context), ); } } diff --git a/lib/presentation/home/widgets/current_upcoming_layout.dart b/lib/presentation/home/widgets/current_upcoming_layout.dart index fb61555d..e9064489 100644 --- a/lib/presentation/home/widgets/current_upcoming_layout.dart +++ b/lib/presentation/home/widgets/current_upcoming_layout.dart @@ -1,9 +1,9 @@ -import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:go_router/go_router.dart'; import '../../../application/crowdaction/spotlight/spotlight_bloc.dart'; -import '../../routes/app_routes.gr.dart'; +import '../../core/routes/app_page.dart'; import '../../shared_widgets/content_placeholder.dart'; import '../../shared_widgets/micro_crowdaction_card.dart'; import '../../themes/constants.dart'; @@ -51,11 +51,8 @@ class _CurrentAndUpcomingLayoutState extends State { ), ), TextButton( - onPressed: () => context.router.push( - widget.isCurrent - ? const CrowdActionBrowseRoute() - : const CrowdActionBrowseRoute(), - ), + onPressed: () => + context.push(AppPage.crowdActionsList.toPath), child: const Text( 'View all', textAlign: TextAlign.center, diff --git a/lib/presentation/home/widgets/password_modal.dart b/lib/presentation/home/widgets/password_modal.dart index 94cbd3c5..8b2d53b5 100644 --- a/lib/presentation/home/widgets/password_modal.dart +++ b/lib/presentation/home/widgets/password_modal.dart @@ -1,12 +1,12 @@ -import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; import '../../../domain/core/i_settings_repository.dart'; import '../../../domain/crowdaction/crowdaction.dart'; import '../../../infrastructure/core/injection.dart'; import '../../../presentation/core/collaction_icons.dart'; -import '../../../presentation/routes/app_routes.gr.dart'; import '../../../presentation/themes/constants.dart'; +import '../../core/routes/app_page.dart'; class PasswordModal extends StatefulWidget { final CrowdAction crowdAction; @@ -147,10 +147,13 @@ class _PasswordModalState extends State { addCrowdActionAccess(); - context.router.replace( - CrowdActionDetailsRoute( - crowdAction: widget.crowdAction, - ), + // TODO - Replace with ID + Navigator.of(context).pop(); + context.push( + AppPage.crowdActionDetails.toPath, + extra: { + 'crowdAction': widget.crowdAction, + }, ); } else { setState(() => _validated = false); @@ -179,8 +182,15 @@ Future showPasswordModal( final accessList = await settingsRepository.getCrowdActionAccessList(); if (accessList.contains(crowdAction.id)) { - context.router.push( - CrowdActionDetailsRoute(crowdAction: crowdAction), + // if (!context.mounted) return; + // TODO: Use id + // TODO: Fix async context access + //ignore: use_build_context_synchronously + context.push( + AppPage.crowdActionDetails.toPath, + extra: { + 'crowdAction': crowdAction, + }, ); } else { showModalBottomSheet( diff --git a/lib/presentation/profile/profile_screen.dart b/lib/presentation/profile/profile_screen.dart index b60e007d..8ccd0dad 100644 --- a/lib/presentation/profile/profile_screen.dart +++ b/lib/presentation/profile/profile_screen.dart @@ -1,15 +1,15 @@ import 'dart:io'; -import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:go_router/go_router.dart'; import 'package:share_plus/share_plus.dart'; import '../../application/auth/auth_bloc.dart'; import '../../application/user/profile/profile_bloc.dart'; import '../core/collaction_icons.dart'; -import '../routes/app_routes.gr.dart'; +import '../core/routes/app_page.dart'; import '../shared_widgets/photo_selector.dart'; import '../shared_widgets/pill_button.dart'; import '../themes/constants.dart'; @@ -78,7 +78,7 @@ class _UserProfilePageState extends State { ), const SizedBox(height: 10), ElevatedButton( - onPressed: () => context.router.push(const SettingsRoute()), + onPressed: () => context.push(AppPage.settings.toPath), style: ElevatedButton.styleFrom( foregroundColor: kPrimaryColor0, backgroundColor: Colors.white, @@ -147,7 +147,7 @@ class _UserProfilePageState extends State { builder: (context) => PhotoSelector( onSelected: (image) { setState(() => _image = image); - context.router.pop("dialog"); + context.pop(); }, ), ); @@ -366,14 +366,14 @@ class _UserProfilePageState extends State { const SizedBox(height: 40), PillButton( text: 'Create account or sign in', - onTap: () => context.router - .push(const AuthRoute()) - .then((_) { + onTap: () { + context.push(AppPage.auth.toPath); + // Refresh profile context .read() .add(GetUserProfile()); - }), + }, ), ], const SizedBox(height: 20), diff --git a/lib/presentation/settings/settings_screen.dart b/lib/presentation/settings/settings_screen.dart index 9be1f7d1..dd69603e 100644 --- a/lib/presentation/settings/settings_screen.dart +++ b/lib/presentation/settings/settings_screen.dart @@ -1,6 +1,6 @@ -import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:go_router/go_router.dart'; import '/application/settings/build_information/build_information_bloc.dart'; import '../../../presentation/utils/launch_url.dart'; @@ -8,7 +8,7 @@ import '../../application/auth/auth_bloc.dart'; import '../../application/user/profile/profile_bloc.dart'; import '../../infrastructure/core/injection.dart'; import '../core/collaction_icons.dart'; -import '../routes/app_routes.gr.dart'; +import '../core/routes/app_page.dart'; import '../shared_widgets/custom_app_bars/custom_appbar.dart'; import '../themes/constants.dart'; import 'widgets/build_information_tile.dart'; @@ -65,24 +65,21 @@ class SettingsPage extends StatelessWidget { title: 'Contact us', icon: CollactionIcons.message, trailingIcon: CollactionIcons.arrow_right, - onTap: () => - context.router.push(const ContactFormRoute()), + onTap: () => context.push(AppPage.contactForm.toPath), ), const SizedBox(height: 15), SettingsListTile( title: 'Onboarding', icon: CollactionIcons.rocket, trailingIcon: CollactionIcons.arrow_right, - onTap: () => - context.router.push(const OnboardingRoute()), + onTap: () => context.push(AppPage.onBoarding.toPath), ), const SizedBox(height: 15), SettingsListTile( title: 'Open source libraries', icon: CollactionIcons.opensource, trailingIcon: CollactionIcons.arrow_right, - onTap: () => - context.router.push(const LicensesRoute()), + onTap: () => context.push(AppPage.licenses.toPath), ), const SizedBox(height: 15), SettingsListTile( @@ -122,7 +119,7 @@ class SettingsPage extends StatelessWidget { onTap: () async { BlocProvider.of(context) .add(const AuthEvent.signedOut()); - await context.router.pop(); + context.pop(); }, ), ], diff --git a/lib/presentation/shared_widgets/micro_crowdaction_card.dart b/lib/presentation/shared_widgets/micro_crowdaction_card.dart index f7dcb3ce..5b29bdf2 100644 --- a/lib/presentation/shared_widgets/micro_crowdaction_card.dart +++ b/lib/presentation/shared_widgets/micro_crowdaction_card.dart @@ -1,11 +1,11 @@ -import 'package:auto_route/auto_route.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:go_router/go_router.dart'; import '../../domain/crowdaction/crowdaction.dart'; +import '../core/routes/app_page.dart'; import '../home/widgets/password_modal.dart'; -import '../routes/app_routes.gr.dart'; import '../themes/constants.dart'; import 'accent_chip.dart'; import 'micro_lock.dart'; @@ -25,10 +25,12 @@ class MicroCrowdActionCard extends StatelessWidget { if (crowdAction.hasPassword) { showPasswordModal(context, crowdAction); } else { - context.router.push( - CrowdActionDetailsRoute( - crowdActionId: crowdAction.id, - ), + // TODO: Use ID & extras + context.push( + AppPage.crowdActionDetails.toPath, + extra: { + 'crowdAction': crowdAction, + }, ); } }, diff --git a/pubspec.lock b/pubspec.lock index 3b22bbd0..76399f9b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -43,20 +43,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.9.0" - auto_route: - dependency: "direct main" - description: - name: auto_route - url: "https://pub.dartlang.org" - source: hosted - version: "5.0.2" - auto_route_generator: - dependency: "direct dev" - description: - name: auto_route_generator - url: "https://pub.dartlang.org" - source: hosted - version: "5.0.2" bloc: dependency: "direct main" description: @@ -506,6 +492,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + go_router: + dependency: "direct main" + description: + name: go_router + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.1" graphs: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index a327fe01..9b72288e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,7 +21,6 @@ environment: sdk: ">=2.18.2 <3.0.0" dependencies: - auto_route: ^5.0.2 bloc: ^8.1.0 cached_network_image: ^3.2.2 country_codes: ^2.2.0 @@ -40,6 +39,7 @@ dependencies: flutter_dotenv: ^5.0.2 freezed_annotation: ^2.2.0 get_it: ^7.2.0 + go_router: ^5.1.1 http: ^0.13.5 image: ^3.2.2 image_cropper: ^3.0.0 @@ -60,7 +60,6 @@ dependencies: webview_flutter: ^3.0.4 dev_dependencies: - auto_route_generator: ^5.0.2 bloc_test: ^9.1.0 build_runner: ^2.3.0 firebase_auth_mocks: ^0.8.6