Skip to content

Commit 394ee16

Browse files
committed
imrpove go router
1 parent b10b72b commit 394ee16

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

app/lib/presentation/navigation/routers.dart

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:app/presentation/ui/pages/splash/splash_page.dart';
55
import 'package:common/core/resource.dart';
66
import 'package:domain/bloc/auth/auth_cubit.dart';
77
import 'package:domain/bloc/auth/auth_state.dart';
8+
import 'package:flutter/widgets.dart';
89
import 'package:flutter_bloc/flutter_bloc.dart';
910
import 'package:go_router/go_router.dart';
1011

@@ -13,7 +14,8 @@ enum Routes {
1314
login,
1415
signup,
1516
app,
16-
home;
17+
home,
18+
placeholder;
1719

1820
String get path => '/$name';
1921
String get subPath => name;
@@ -41,60 +43,61 @@ class Routers {
4143
if (state is RSuccess) {
4244
switch (state.data) {
4345
case AuthStateAuthenticated _:
46+
debugPrint('User is authenticated');
4447
Routes.app.nav();
4548
break;
4649
case AuthStateUnauthenticated _:
50+
debugPrint('User is unauthenticated');
4751
Routes.auth.nav();
4852
break;
4953
case _:
5054
}
5155
}
5256
},
53-
child: const SplashPage(instant: true),
57+
child: const SplashPage(),
5458
);
5559
},
5660
routes: [
57-
GoRoute(
58-
name: Routes.auth.name,
59-
path: Routes.auth.path,
61+
ShellRoute(
62+
builder: (context, state, child) => child,
6063
redirect: (context, state) {
6164
if (context.read<AuthCubit>().isLoggedIn()) {
62-
return '${Routes.app.path}${Routes.home.path}';
65+
return Routes.app.path;
6366
}
64-
65-
/// Continue to auth routes
6667
return null;
6768
},
6869
routes: [
6970
GoRoute(
70-
name: Routes.login.name,
71-
path: Routes.login.subPath,
71+
name: Routes.auth.name,
72+
path: Routes.auth.path,
7273
builder: (context, state) => const LoginPage(),
7374
),
7475
GoRoute(
7576
name: Routes.signup.name,
76-
path: Routes.signup.subPath,
77+
path: '${Routes.auth.path}${Routes.signup.path}',
7778
builder: (context, state) => const SignUpPage(),
7879
),
7980
],
8081
),
81-
GoRoute(
82-
name: Routes.app.name,
83-
path: Routes.app.path,
82+
ShellRoute(
83+
builder: (context, state, child) => child,
8484
redirect: (context, state) {
8585
if (!context.read<AuthCubit>().isLoggedIn()) {
86-
return '${Routes.auth.path}${Routes.login.path}';
86+
return Routes.auth.path;
8787
}
88-
89-
/// Continue to app routes
9088
return null;
9189
},
9290
routes: [
9391
GoRoute(
94-
name: Routes.home.name,
95-
path: Routes.home.subPath,
92+
name: Routes.app.name,
93+
path: Routes.app.path,
9694
builder: (context, state) => const HomePage(),
9795
),
96+
GoRoute(
97+
name: Routes.placeholder.name,
98+
path: "${Routes.app.path}${Routes.placeholder.path}",
99+
builder: (context, state) => const Placeholder(),
100+
),
98101
],
99102
),
100103
],

app/lib/presentation/ui/pages/login/login_page.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:app/main/init.dart';
2+
import 'package:app/presentation/navigation/routers.dart';
23
import 'package:app/presentation/resources/resources.dart';
34
import 'package:app/presentation/ui/custom/app_theme_switch.dart';
45
import 'package:app/presentation/ui/custom/loading_screen.dart';
@@ -32,10 +33,8 @@ class LoginPage extends StatelessWidget {
3233
child: ElevatedButton(
3334
child: const Text('Login'),
3435
onPressed: () {
35-
_authCubit.login(
36-
'Rootstrap',
37-
'12345678',
38-
);
36+
Routes.signup.nav();
37+
//_authCubit.login('Rootstrap', '12345678');
3938
},
4039
),
4140
),

0 commit comments

Comments
 (0)