2

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?

Turkey
  • 346
  • 4
  • 16
  • https://pub.dev/documentation/flutter_cubit/latest/`MultiCubitProvider( providers: [ CubitProvider( create: (BuildContext context) => CubitA(), ), CubitProvider( create: (BuildContext context) => CubitB(), ), CubitProvider( create: (BuildContext context) => CubitC(), ), ], child: ChildA(), )` – lava Feb 17 '22 at 04:49

1 Answers1

2

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

Husen
  • 185
  • 1
  • 10
  • Thank 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. – Turkey Mar 02 '22 at 09:13