Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter : Multiple Cubits Example

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?

like image 344
Turkey Avatar asked Sep 14 '25 06:09

Turkey


1 Answers

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

like image 126
Husen Avatar answered Sep 16 '25 18:09

Husen