-
Notifications
You must be signed in to change notification settings - Fork 0
Improve app navigation. #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
e383801
b10b72b
394ee16
15f9331
24a3a95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,12 +6,13 @@ import 'package:data/init.dart'; | |||||||
| import 'package:domain/init.dart'; | ||||||||
| import 'package:flutter/material.dart'; | ||||||||
| import 'package:get_it/get_it.dart'; | ||||||||
| import 'package:url_strategy/url_strategy.dart'; | ||||||||
| import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | ||||||||
|
|
||||||||
|
|
||||||||
| void init() async { | ||||||||
| WidgetsFlutterBinding.ensureInitialized(); | ||||||||
|
||||||||
| WidgetsFlutterBinding.ensureInitialized(); | |
| WidgetsFlutterBinding.ensureInitialized(); | |
| // Use path-based URLs instead of hash-based URLs for better SEO and cleaner URLs. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,32 +1,102 @@ | ||||||
| import 'package:app/main/init.dart'; | ||||||
| import 'package:app/presentation/ui/pages/home/home_page.dart'; | ||||||
| import 'package:app/presentation/ui/pages/login/login_page.dart'; | ||||||
| import 'package:app/presentation/ui/pages/sign_up/sign_up_page.dart'; | ||||||
| import 'package:app/presentation/ui/pages/splash/splash_page.dart'; | ||||||
| import 'package:common/core/resource.dart'; | ||||||
| import 'package:domain/bloc/auth/auth_cubit.dart'; | ||||||
| import 'package:domain/bloc/auth/auth_state.dart'; | ||||||
| import 'package:flutter_bloc/flutter_bloc.dart'; | ||||||
| import 'package:go_router/go_router.dart'; | ||||||
|
|
||||||
| enum Routes { | ||||||
| auth, | ||||||
| login, | ||||||
| signUp, | ||||||
| app, | ||||||
| home; | ||||||
|
|
||||||
| String get path => '/$name'; | ||||||
|
||||||
| String get subPath => name; | ||||||
|
|
||||||
| void nav({Object? extra}) { | ||||||
| Routers.authRouter.goNamed( | ||||||
| name, | ||||||
| extra: extra, | ||||||
| ); | ||||||
| } | ||||||
|
amaury901130 marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| static GoRouter get router => Routers.authRouter; | ||||||
| } | ||||||
|
Comment on lines
+13
to
+37
|
||||||
|
|
||||||
| class Routers { | ||||||
| static GoRouter authRouter = GoRouter( | ||||||
| initialLocation: "/splash", | ||||||
| initialLocation: '/', | ||||||
| routes: [ | ||||||
| GoRoute( | ||||||
| name: "login", | ||||||
| path: "/login", | ||||||
| builder: (context, state) => const LoginPage(), | ||||||
| ), | ||||||
| GoRoute( | ||||||
| name: "splash", | ||||||
| path: "/splash", | ||||||
| builder: (context, state) => const SplashPage(), | ||||||
| ), | ||||||
| GoRoute( | ||||||
| name: "signUp", | ||||||
| path: "/signUp", | ||||||
| builder: (context, state) => const SignUpPage(), | ||||||
| ), | ||||||
| GoRoute( | ||||||
| name: "home", | ||||||
| path: "/home", | ||||||
| builder: (context, state) => const HomePage(), | ||||||
| path: '/', | ||||||
| builder: (context, state) { | ||||||
| return BlocListener<AuthCubit, Resource>( | ||||||
| listener: (_, state) { | ||||||
| if (state is RSuccess) { | ||||||
| switch (state.data) { | ||||||
| case AuthStateAuthenticated _: | ||||||
| Routes.app.nav(); | ||||||
| break; | ||||||
| case AuthStateUnauthenticated _: | ||||||
| Routes.auth.nav(); | ||||||
| break; | ||||||
| case _: | ||||||
| } | ||||||
| } | ||||||
| }, | ||||||
|
amaury901130 marked this conversation as resolved.
Outdated
|
||||||
| child: const SplashPage(instant: true), | ||||||
| ); | ||||||
| }, | ||||||
| routes: [ | ||||||
| GoRoute( | ||||||
| name: Routes.auth.name, | ||||||
| path: Routes.auth.path, | ||||||
|
amaury901130 marked this conversation as resolved.
Outdated
|
||||||
| path: Routes.auth.path, | |
| path: Routes.auth.subPath, |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The redirect logic has a critical issue: when accessing /auth route directly, it will be constructed with path '/$name' which evaluates to '/auth'. However, the redirect at line 62 returns '${Routes.app.path}${Routes.home.path}' which evaluates to '/app/home'. This creates inconsistent path construction - the auth route uses path while the redirect uses nested path concatenation. This may cause navigation issues.
Consider making the path construction consistent: either use Routes.app.path + '/' + Routes.home.subPath or restructure to avoid manual path concatenation.
| return '${Routes.app.path}${Routes.home.path}'; | |
| return '${Routes.app.path}/${Routes.home.subPath}'; |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nested route path is incorrect. Since this is a child route under '/', the path should be relative (e.g., 'app') not absolute ('/app'). Using Routes.app.path which returns '/$name' will create the path '//app'. Change to use Routes.app.subPath or a relative path string 'app'.
| path: Routes.app.path, | |
| path: Routes.app.subPath, |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The builder for the /app route returns const SplashPage() without the instant parameter, which defaults to true based on line 7 of splash_page.dart. However, this causes the splash screen to call _authCubit.onValidate() immediately, which will trigger navigation back through the BlocListener at the root route. This creates a circular navigation pattern and unnecessary re-validation.
Consider removing this builder entirely or using a different widget, as the app route should only serve as a container for its child routes, not display a splash screen.
| builder: (context, state) => const SplashPage(), | |
| builder: (context, state) => const SizedBox.shrink(), |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -18,7 +18,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev | |||
| version: 1.0.0+1 | ||||
|
|
||||
| environment: | ||||
| sdk: '>=3.0.0 <4.0.0' | ||||
| sdk: ">=3.0.0 <4.0.0" | ||||
|
|
||||
| dependencies: | ||||
| flutter: | ||||
|
|
@@ -35,7 +35,7 @@ dependencies: | |||
| package_info_plus: ^8.3.0 | ||||
| permission_handler: ^11.4.0 | ||||
| universal_html: ^2.2.2 | ||||
| go_router: ^7.0.1 | ||||
| go_router: ^17.0.0 | ||||
| equatable: ^2.0.5 | ||||
| firebase_core: ^3.13.0 | ||||
| url_strategy: ^0.2.0 | ||||
|
||||
| url_strategy: ^0.2.0 |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,9 @@ class AuthCubit extends BaseCubit<AuthState> { | |||||||||||||
| isLogOut(); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
amaury901130 marked this conversation as resolved.
|
||||||||||||||
| bool isLoggedIn() => | ||||||||||||||
| state is RSuccess && (state as RSuccess).data is AuthStateAuthenticated; | ||||||||||||||
|
||||||||||||||
| bool isLoggedIn() => | |
| state is RSuccess && (state as RSuccess).data is AuthStateAuthenticated; | |
| // Use pattern matching for safer and more concise type checking. | |
| bool isLoggedIn() { | |
| return state case RSuccess(data: AuthStateAuthenticated()) => true, _ => false; | |
| } |
Uh oh!
There was an error while loading. Please reload this page.