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 home = [initial, explore, setting]; static final GlobalKey navigatorKey = GlobalKey(); static GoRouter createRouter = GoRouter( navigatorKey: navigatorKey, initialLocation: initial, routes: [ // GoRoute( // path: initial, // builder: (BuildContext context, GoRouterState state) { // return BlocConsumer( // 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: [ // GoRoute( // path: product, // builder: (BuildContext context, GoRouterState state) { // return ProductPage(); // }, // routes: [], // ), // ], // ), StatefulShellRoute.indexedStack( builder: (context, state, navigationShell) => BlocBuilder( 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: [], ), ]), ]), StatefulShellBranch(routes: [ GoRoute( path: explore, builder: (context, state) => ExploreScreen(), ), ]), StatefulShellBranch(routes: [ GoRoute( path: setting, builder: (context, state) => SettingScreen(), ), ]), ], ), ], ); }