vessel_flutter

Creator: coderz1093

Last updated:

0 purchases

vessel_flutter Image
vessel_flutter Images
Add to Cart

Description:

vessel flutter

vessel for Flutter
For more information about DI itself see vessel
Getting started #
Wrap your app in ProviderScope widget:
void main() {
runApp(
ProviderScope(child: App())
);
}
copied to clipboard
Read your providers with of extension method:
GestureDetector(
onTap: () => myProvider.of(context).doSomething()
child: ...
);
copied to clipboard
Each ProviderScope introduces new ProviderContainer, which becomes child of the previous container.
When ProviderScope widget disposes, it disposes ProviderContainer with it.
Overriding and scoping #
It's possible to override provider with another one:
ProviderScope(
overrides: [
myProvider.overrideWith(anotherProvider),
],
child: ...
)
copied to clipboard
Or just scope it:
ProviderScope(
overrides: [
myProvider.scope(),
],
child: ...
)
copied to clipboard
Pass parent #
ProviderScope takes its parent from the BuildContext. But you could override it with parent constructor parameter.
It could be useful with dialogs:
ProviderScope(
overrides: [myVmProvider.scoped()],
child: Builder(
builder: (context) => GestureDetector(
onTap: () {
final container = UncontrolledProviderScope.of(context);
showAlertDialog(
builder: (context) => ProviderScope(
parent: container,
child: ...
)
)
},
child: ...
)
)
)
copied to clipboard
Now your dialog will receive all scoped providers from the parent screen.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.