106 lines
3.5 KiB
Dart
106 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:proxibuy/presentation/providers/cubit/user_info_cubit.dart';
|
|
import 'package:proxibuy/presentation/ui/screens/auth/auth_page.dart';
|
|
import 'package:proxibuy/presentation/ui/screens/home/explore_screen.dart';
|
|
import 'package:proxibuy/presentation/ui/screens/home/home_page.dart';
|
|
import 'package:proxibuy/presentation/ui/screens/home/home_screen.dart';
|
|
import 'package:proxibuy/presentation/ui/screens/home/setting_screen.dart';
|
|
import 'package:proxibuy/presentation/ui/screens/product/product_page.dart';
|
|
|
|
class AppRouter {
|
|
static final initial = '/';
|
|
static final explore = '/explore';
|
|
static final setting = '/settings';
|
|
static final product = '/product';
|
|
|
|
static List<String> home = [initial, explore, setting];
|
|
|
|
static final GlobalKey<NavigatorState> navigatorKey =
|
|
GlobalKey<NavigatorState>();
|
|
|
|
static GoRouter createRouter = GoRouter(
|
|
navigatorKey: navigatorKey,
|
|
initialLocation: initial,
|
|
routes: [
|
|
// GoRoute(
|
|
// path: initial,
|
|
// builder: (BuildContext context, GoRouterState state) {
|
|
// return BlocConsumer<UserInfoCubit, UserInfoState>(
|
|
// listener: (context, state) {
|
|
// if (state is UserInfoSuccess || state is UserInfoFail) {
|
|
// FlutterNativeSplash.remove();
|
|
// }
|
|
// },
|
|
// builder: (context, state) {
|
|
// if (state is UserInfoSuccess) {
|
|
// return const HomePage();
|
|
// } else {
|
|
// return const AuthPage();
|
|
// }
|
|
// },
|
|
// );
|
|
// },
|
|
// routes: <RouteBase>[
|
|
// GoRoute(
|
|
// path: product,
|
|
// builder: (BuildContext context, GoRouterState state) {
|
|
// return ProductPage();
|
|
// },
|
|
// routes: <RouteBase>[],
|
|
// ),
|
|
// ],
|
|
// ),
|
|
|
|
StatefulShellRoute.indexedStack(
|
|
builder: (context, state, navigationShell) =>
|
|
BlocBuilder<UserInfoCubit, UserInfoState>(
|
|
builder: (context, userState) {
|
|
if (userState is UserInfoSuccess) {
|
|
if (home.contains(state.fullPath)) {
|
|
return HomePage(child: navigationShell);
|
|
} else {
|
|
return navigationShell;
|
|
}
|
|
} else {
|
|
return AuthPage();
|
|
}
|
|
},
|
|
),
|
|
branches: [
|
|
StatefulShellBranch(routes: [
|
|
GoRoute(
|
|
path: initial,
|
|
builder: (context, state) {
|
|
return HomeScreen();
|
|
},
|
|
routes: [
|
|
GoRoute(
|
|
path: product,
|
|
builder: (BuildContext context, GoRouterState state) {
|
|
return ProductPage();
|
|
},
|
|
routes: <RouteBase>[],
|
|
),
|
|
]),
|
|
]),
|
|
StatefulShellBranch(routes: [
|
|
GoRoute(
|
|
path: explore,
|
|
builder: (context, state) => ExploreScreen(),
|
|
),
|
|
]),
|
|
StatefulShellBranch(routes: [
|
|
GoRoute(
|
|
path: setting,
|
|
builder: (context, state) => SettingScreen(),
|
|
),
|
|
]),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|