From 3615f9d2212274fdf95c4d431e8291ac74e968a2 Mon Sep 17 00:00:00 2001 From: Andrea Bizzotto Date: Tue, 26 Nov 2024 17:30:44 +0000 Subject: [PATCH] Update app startup logic to be compatible with URL-based navigation and deep links (#158) * Start updating the app startup logic * Remove the /startup route (that was silly) --- lib/src/app.dart | 6 ++ lib/src/routing/app_router.dart | 24 +----- lib/src/routing/app_startup.dart | 13 ++++ pubspec.lock | 124 +++++++++++++++---------------- 4 files changed, 83 insertions(+), 84 deletions(-) diff --git a/lib/src/app.dart b/lib/src/app.dart index a7a6fcd1..7d0d55d2 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:starter_architecture_flutter_firebase/src/routing/app_router.dart'; +import 'package:starter_architecture_flutter_firebase/src/routing/app_startup.dart'; class MyApp extends ConsumerWidget { const MyApp({super.key}); @@ -12,6 +13,11 @@ class MyApp extends ConsumerWidget { final goRouter = ref.watch(goRouterProvider); return MaterialApp.router( routerConfig: goRouter, + builder: (_, child) { + return AppStartupWidget( + onLoaded: (_) => child!, + ); + }, theme: ThemeData( colorSchemeSeed: primaryColor, unselectedWidgetColor: Colors.grey, diff --git a/lib/src/routing/app_router.dart b/lib/src/routing/app_router.dart index 6cec69aa..8fc04f90 100644 --- a/lib/src/routing/app_router.dart +++ b/lib/src/routing/app_router.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:riverpod/riverpod.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; -import 'package:starter_architecture_flutter_firebase/src/routing/app_startup.dart'; import 'package:starter_architecture_flutter_firebase/src/features/authentication/data/firebase_auth_repository.dart'; import 'package:starter_architecture_flutter_firebase/src/features/authentication/presentation/custom_profile_screen.dart'; import 'package:starter_architecture_flutter_firebase/src/features/authentication/presentation/custom_sign_in_screen.dart'; @@ -43,18 +42,12 @@ enum AppRoute { @riverpod GoRouter goRouter(Ref ref) { - // rebuild GoRouter when app startup state changes - final appStartupState = ref.watch(appStartupProvider); final authRepository = ref.watch(authRepositoryProvider); return GoRouter( initialLocation: '/signIn', navigatorKey: _rootNavigatorKey, debugLogDiagnostics: true, redirect: (context, state) { - // If the app is still initializing, show the /startup route - if (appStartupState.isLoading || appStartupState.hasError) { - return '/startup'; - } final onboardingRepository = ref.read(onboardingRepositoryProvider).requireValue; final didCompleteOnboarding = onboardingRepository.isOnboardingComplete(); @@ -69,14 +62,11 @@ GoRouter goRouter(Ref ref) { } final isLoggedIn = authRepository.currentUser != null; if (isLoggedIn) { - if (path.startsWith('/startup') || - path.startsWith('/onboarding') || - path.startsWith('/signIn')) { + if (path.startsWith('/onboarding') || path.startsWith('/signIn')) { return '/jobs'; } } else { - if (path.startsWith('/startup') || - path.startsWith('/onboarding') || + if (path.startsWith('/onboarding') || path.startsWith('/jobs') || path.startsWith('/entries') || path.startsWith('/account')) { @@ -87,16 +77,6 @@ GoRouter goRouter(Ref ref) { }, refreshListenable: GoRouterRefreshStream(authRepository.authStateChanges()), routes: [ - GoRoute( - path: '/startup', - pageBuilder: (context, state) => NoTransitionPage( - child: AppStartupWidget( - // * This is just a placeholder - // * The loaded route will be managed by GoRouter on state change - onLoaded: (_) => const SizedBox.shrink(), - ), - ), - ), GoRoute( path: '/onboarding', name: AppRoute.onboarding.name, diff --git a/lib/src/routing/app_startup.dart b/lib/src/routing/app_startup.dart index 16c09d39..fa413ec4 100644 --- a/lib/src/routing/app_startup.dart +++ b/lib/src/routing/app_startup.dart @@ -13,6 +13,9 @@ Future appStartup(Ref ref) async { // ensure dependent providers are disposed as well ref.invalidate(onboardingRepositoryProvider); }); + // Uncomment this to test that URL-based navigation and deep linking works + // even when there's a delay in the app startup logic + // await Future.delayed(Duration(seconds: 1)); // await for all initialization code to be complete before returning await ref.watch(onboardingRepositoryProvider.future); } @@ -76,3 +79,13 @@ class AppStartupErrorWidget extends StatelessWidget { ); } } + +class AppStartupDataWidget extends StatelessWidget { + const AppStartupDataWidget({super.key, required this.child}); + final Widget child; + + @override + Widget build(BuildContext context) { + return child; + } +} diff --git a/pubspec.lock b/pubspec.lock index c3036292..065ead4b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -42,10 +42,10 @@ packages: dependency: transitive description: name: args - sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6 + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 url: "https://pub.dev" source: hosted - version: "2.6.0" + version: "2.4.2" async: dependency: transitive description: @@ -82,10 +82,10 @@ packages: dependency: transitive description: name: build_daemon - sha256: "79b2aef6ac2ed00046867ed354c88778c9c0f029df8a20fe10b5436826721ef9" + sha256: "0343061a33da9c5810b2d6cee51945127d8f4c060b7fbdd9d54917f0a3feaaa1" url: "https://pub.dev" source: hosted - version: "4.0.2" + version: "4.0.1" build_resolvers: dependency: transitive description: @@ -106,10 +106,10 @@ packages: dependency: transitive description: name: build_runner_core - sha256: f8126682b87a7282a339b871298cc12009cb67109cfa1614d6436fb0289193e0 + sha256: "4ae8ffe5ac758da294ecf1802f2aff01558d8b1b00616aa7538ea9a8a5d50799" url: "https://pub.dev" source: hosted - version: "7.3.2" + version: "7.3.0" built_collection: dependency: transitive description: @@ -122,10 +122,10 @@ packages: dependency: transitive description: name: built_value - sha256: c7913a9737ee4007efedaffc968c049fd0f3d0e49109e778edc10de9426005cb + sha256: fedde275e0a6b798c3296963c5cd224e3e1b55d0e478d5b7e65e6b540f363a0e url: "https://pub.dev" source: hosted - version: "8.9.2" + version: "8.9.1" characters: dependency: transitive description: @@ -154,10 +154,10 @@ packages: dependency: transitive description: name: cli_util - sha256: ff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c + sha256: c05b7406fdabc7a49a3929d4af76bcaccbbffcbcdcf185b082e1ae07da323d19 url: "https://pub.dev" source: hosted - version: "0.4.2" + version: "0.4.1" clock: dependency: transitive description: @@ -194,10 +194,10 @@ packages: dependency: transitive description: name: code_builder - sha256: "0ec10bf4a89e4c613960bf1e8b42c64127021740fb21640c29c909826a5eea3e" + sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37 url: "https://pub.dev" source: hosted - version: "4.10.1" + version: "4.10.0" collection: dependency: transitive description: @@ -210,18 +210,18 @@ packages: dependency: transitive description: name: convert - sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" url: "https://pub.dev" source: hosted - version: "3.1.2" + version: "3.1.1" crypto: dependency: transitive description: name: crypto - sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab url: "https://pub.dev" source: hosted - version: "3.0.6" + version: "3.0.3" cupertino_icons: dependency: "direct main" description: @@ -266,10 +266,10 @@ packages: dependency: transitive description: name: dart_style - sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab" + sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9" url: "https://pub.dev" source: hosted - version: "2.3.7" + version: "2.3.6" desktop_webview_auth: dependency: transitive description: @@ -306,18 +306,18 @@ packages: dependency: transitive description: name: ffi - sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6" + sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" url: "https://pub.dev" source: hosted - version: "2.1.3" + version: "2.1.2" file: dependency: transitive description: name: file - sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4 + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" url: "https://pub.dev" source: hosted - version: "7.0.1" + version: "7.0.0" firebase_auth: dependency: "direct main" description: @@ -426,10 +426,10 @@ packages: dependency: transitive description: name: fixnum - sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -478,18 +478,18 @@ packages: dependency: transitive description: name: freezed_annotation - sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2 + sha256: c3fd9336eb55a38cc1bbd79ab17573113a8deccd0ecbbf926cca3c62803b5c2d url: "https://pub.dev" source: hosted - version: "2.4.4" + version: "2.4.1" frontend_server_client: dependency: transitive description: name: frontend_server_client - sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694 + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "3.2.0" glob: dependency: transitive description: @@ -510,10 +510,10 @@ packages: dependency: transitive description: name: graphs - sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0" + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 url: "https://pub.dev" source: hosted - version: "2.3.2" + version: "2.3.1" hotreloader: dependency: transitive description: @@ -566,18 +566,18 @@ packages: dependency: transitive description: name: js - sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 url: "https://pub.dev" source: hosted - version: "0.7.1" + version: "0.6.7" json_annotation: dependency: transitive description: name: json_annotation - sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 url: "https://pub.dev" source: hosted - version: "4.9.0" + version: "4.8.1" leak_tracker: dependency: transitive description: @@ -614,10 +614,10 @@ packages: dependency: transitive description: name: logging - sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.2.0" macros: dependency: transitive description: @@ -654,10 +654,10 @@ packages: dependency: transitive description: name: mime - sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6" + sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "1.0.5" mocktail: dependency: "direct dev" description: @@ -686,10 +686,10 @@ packages: dependency: transitive description: name: path_parsing - sha256: "883402936929eac138ee0a45da5b0f2c80f89913e6dc3bf77eb65b84b409c6ca" + sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.0.1" path_provider_linux: dependency: transitive description: @@ -710,10 +710,10 @@ packages: dependency: transitive description: name: path_provider_windows - sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7 + sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170" url: "https://pub.dev" source: hosted - version: "2.3.0" + version: "2.2.1" petitparser: dependency: transitive description: @@ -726,10 +726,10 @@ packages: dependency: transitive description: name: platform - sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984" + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" url: "https://pub.dev" source: hosted - version: "3.1.6" + version: "3.1.4" plugin_platform_interface: dependency: transitive description: @@ -758,10 +758,10 @@ packages: dependency: transitive description: name: pubspec_parse - sha256: c799b721d79eb6ee6fa56f00c04b472dcd44a30d258fac2174a6ec57302678f8 + sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367 url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.2.3" random_string: dependency: "direct dev" description: @@ -886,10 +886,10 @@ packages: dependency: transitive description: name: shelf_web_socket - sha256: cc36c297b52866d203dbf9332263c94becc2fe0ceaa9681d07b6ef9807023b67 + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "1.0.4" sky_engine: dependency: transitive description: flutter @@ -987,10 +987,10 @@ packages: dependency: transitive description: name: typed_data - sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c url: "https://pub.dev" source: hosted - version: "1.4.0" + version: "1.3.2" uuid: dependency: transitive description: @@ -1011,10 +1011,10 @@ packages: dependency: transitive description: name: vector_graphics_codec - sha256: "2430b973a4ca3c4dbc9999b62b8c719a160100dcbae5c819bae0cacce32c9cdb" + sha256: c86987475f162fadff579e7320c7ddda04cd2fdeffbe1129227a85d9ac9e03da url: "https://pub.dev" source: hosted - version: "1.1.12" + version: "1.1.11+1" vector_graphics_compiler: dependency: transitive description: @@ -1055,30 +1055,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" - web_socket: + web_socket_channel: dependency: transitive description: - name: web_socket - sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83" + name: web_socket_channel + sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b url: "https://pub.dev" source: hosted - version: "0.1.6" - web_socket_channel: + version: "2.4.0" + win32: dependency: transitive description: - name: web_socket_channel - sha256: "9f187088ed104edd8662ca07af4b124465893caf063ba29758f97af57e61da8f" + name: win32 + sha256: "8cb58b45c47dcb42ab3651533626161d6b67a2921917d8d429791f76972b3480" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "5.3.0" xdg_directories: dependency: transitive description: name: xdg_directories - sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15" + sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.0.4" xml: dependency: transitive description: