I can’t use the MultiBlocProvider in the root widget, because when the user logs out of the account, the data in the bloc is saved.
Router
StatefulShellBranch(
navigatorKey: _rentShellNavigatorKey,
routes: <RouteBase>[
GoRoute(
path: AppRouter.rentCarList.routePath,
pageBuilder: (BuildContext context, GoRouterState state) => const NoTransitionPage<dynamic> (child: RentCarsScreen()),
routes: <RouteBase>[
GoRoute(
path: "${AppRouter.rentCarDesc.routeName}/:id",
name: AppRouter.rentCarDesc.routeName,
builder: (BuildContext context, GoRouterState state) =>
RentCarDescScreen(id: state.pathParameters["id"]!),
routes: <RouteBase>[
GoRoute(
path: AppRouter.carReservation.routeName,
name: AppRouter.carReservation.routeName,
builder: (BuildContext context, GoRouterState state) =>
CarReservationScreen(id: state.pathParameters["id"]!),
),
]
),
])
]),
RentCarsScreen
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF0F2F4),
body: BlocProvider<RentCarBloc>(
create: (BuildContext context) => locator<RentCarBloc>
()..add(GetRentCarListEvent()),
child: BlocBuilder<RentCarBloc, RentCarState>(
builder: (BuildContext context, RentCarState state) {
//ui code
RentCarDescScreen
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF0F2F4),
body: BlocBuilder<RentCarBloc, RentCarState>(
builder: (BuildContext context, RentCarState state) {
// ui code
2
Answers
Replcace
to
Then in RentCarsScreen, if you want to add event, do like this