119 lines
4.1 KiB
Dart
119 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:proxibuy/presentation/providers/category/cubit/category_cubit.dart';
|
|
import 'package:proxibuy/presentation/providers/user_info_cubit.dart';
|
|
import 'package:proxibuy/presentation/ui/screens/auth/auth_page.dart';
|
|
import 'package:proxibuy/presentation/ui/screens/categories/categories_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/widgets/navigations/drop_down_demo2.dart';
|
|
|
|
class AppRouter {
|
|
static final initial = '/';
|
|
static final explore = '/explore';
|
|
static final setting = '/settings';
|
|
static final product = '/product';
|
|
static final categories = '/categories';
|
|
|
|
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 DropDownDemo3();
|
|
},
|
|
),
|
|
GoRoute(
|
|
path: '$categories/:id',
|
|
builder: (BuildContext context, GoRouterState state) {
|
|
final id = state.pathParameters['id']!;
|
|
return BlocProvider<CategoryCubit>(
|
|
create: (context) => CategoryCubit()..getCategory(id),
|
|
child: CategoriesPage(
|
|
id: id,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
]),
|
|
]),
|
|
StatefulShellBranch(routes: [
|
|
GoRoute(
|
|
path: explore,
|
|
builder: (context, state) => ExploreScreen(),
|
|
),
|
|
]),
|
|
StatefulShellBranch(routes: [
|
|
GoRoute(
|
|
path: setting,
|
|
builder: (context, state) => SettingScreen(),
|
|
),
|
|
]),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|