Flutter : Multiple Cubits Example
you can use MultiBlocProvider for cubits and you will not have any problems.
MultiBlocProvider(
providers: [
BlocProvider(
create: (BuildContext context) => MyCubit())
],
child: Container())
you will probably need Bloc-to-Bloc Communication too
these bloc example projects, which use multiple blocs and cubits in a project that may help you. flutter_todos, flutter_shopping_cart, flutter_firebase_login
Turkey
Updated on November 29, 2022Comments
-
Turkey over 1 year
I'm using Cubits for state management in my Flutter app.
It is my favourite state-management approach so far.However, I now want to get a little more complex, and have multiple cubits, controlling different bits of state each (eg. one is for login-related state, another for config/settings state, and another for the main app state).
I'm trying to find an example of how to do multiple cubits and I'm not finding anything.
With the BLoc approach we would use MultiBlocProvider.
Is there an equivalent to the MultiBlocProvider for cubits?
Or, can you point me at a tutorial that demonstrates using multiple cubits in the one app?-
lava about 2 yearspub.dev/documentation/flutter_cubit/latest
MultiCubitProvider( providers: [ CubitProvider<CubitA>( create: (BuildContext context) => CubitA(), ), CubitProvider<CubitB>( create: (BuildContext context) => CubitB(), ), CubitProvider<CubitC>( create: (BuildContext context) => CubitC(), ), ], child: ChildA(), )
-
-
Turkey about 2 yearsThank you - and, yes, my own research told me that should work - I haven't got back to implementing it yet, but once I have and confirm it works I'll mark this as the correct answer.