Skip to content
This repository has been archived by the owner on Jul 9, 2020. It is now read-only.

CubitModule? #43

Closed
magillus opened this issue Jul 2, 2020 · 3 comments
Closed

CubitModule? #43

magillus opened this issue Jul 2, 2020 · 3 comments
Assignees
Labels
question Further information is requested
Projects

Comments

@magillus
Copy link

magillus commented Jul 2, 2020

Hello, so far I love this - after reading this package's documentation.

I have question if it is worth to add a CubitModule that would combine with MultiCubitProvider.
It would have list of Cubits needed for a child, quite handy if common list of CubitProvider is used in many places.

MultiCubitProvider(
  providers: [
    CubitProvider<CubitA>(
      create: (BuildContext context) => CubitA(),
    ),
    CubitProvider<CubitB>(
      create: (BuildContext context) => CubitB(),
    ),
    CubitProvider<CubitC>(
      create: (BuildContext context) => CubitC(),
    ),
  ],
  child: ChildA(),
)

could be replaced with:

MultiCubitProvider(
  module: MyCubitModule(),
  child: ChildA(),
)

Optional the modules but that would require also check if same Cubit was not already provided in other module.
After digging into source of this and Provider, that might be not worth adding.

Also this can be resolved with static list of providers, if their initialization and create method isn't called until needed.

@magillus
Copy link
Author

magillus commented Jul 2, 2020

Now as I see the callbacks to create the CubitA/CubitB/CubitC will not have options for current build context.

@felangel
Copy link
Owner

felangel commented Jul 2, 2020

Hey @magillus 👋
Thanks for opening an issue and for the positive feedback!

I've seen projects have their version of this by extracting the MultiProvider into a separate widget like:

class MyCubitModule extends MultiCubitProvider {
  MyCubitModule({@required Widget child}) : super(providers: [...], child: child);
}

Then you can use it in your widget tree like:

MyCubitModule(child: ChildA());

Let me know what you think and thanks again for opening an issue! 🙏

@felangel felangel self-assigned this Jul 2, 2020
@felangel felangel added question Further information is requested waiting for response Waiting for follow up labels Jul 2, 2020
@felangel felangel added this to To do in cubit via automation Jul 2, 2020
@magillus magillus closed this as completed Jul 3, 2020
cubit automation moved this from To do to Done Jul 3, 2020
@felangel felangel removed the waiting for response Waiting for follow up label Jul 3, 2020
@magillus
Copy link
Author

magillus commented Jul 3, 2020

That sounds like a good solution, I didn't come with possibility, since myself not using provider much.
Thank you for explanation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
No open projects
cubit
  
Done
Development

No branches or pull requests

2 participants