vessel_flutter 3.1.0 copy "vessel_flutter: ^3.1.0" to clipboard
vessel_flutter: ^3.1.0 copied to clipboard

vessel for 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())
  );
}

Read your providers with of extension method:

GestureDetector(
  onTap: () => myProvider.of(context).doSomething()
  child: ...
);

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: ...
)

Or just scope it:

ProviderScope(
  overrides: [
    myProvider.scope(),
  ],
  child: ...
)

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: ...
    )
  )
)

Now your dialog will receive all scoped providers from the parent screen.

0
likes
140
pub points
0%
popularity

Publisher

unverified uploader

vessel for Flutter

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

collection, flutter, meta, vessel

More

Packages that depend on vessel_flutter