proxibuy/lib/core/routes/app_router.dart

79 lines
2.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/home_page.dart';
class AppRouter {
static final initial = '/';
static final home = '/home';
static final explore = '/explore';
static final setting = '/settings';
static final GlobalKey<NavigatorState> navigatorKey =
GlobalKey<NavigatorState>();
GoRouter createRouter = GoRouter(
navigatorKey: navigatorKey,
initialLocation: home,
routes: [
GoRoute(
path: home,
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>[],
),
// StatefulShellRoute.indexedStack(
// builder: (context, state, navigationShell) =>
// BlocBuilder<UserInfoCubit, UserInfoState>(
// builder: (context, state) {
// if (state is UserInfoSuccess) {
// return CustomBottomNav(child: navigationShell);
// } else {
// return AuthPage();
// }
// },
// ),
// branches: [
// StatefulShellBranch(routes: [
// GoRoute(
// path: initial,
// builder: (context, state) {
// return HomeScreen();
// },
// ),
// ]),
// StatefulShellBranch(routes: [
// GoRoute(
// path: explore,
// builder: (context, state) => ExploreScreen(),
// ),
// ]),
// StatefulShellBranch(routes: [
// GoRoute(
// path: setting,
// builder: (context, state) => SettingScreen(),
// ),
// ]),
// ],
// ),
],
);
}