Flutter

Flutter integration

Place Ark DI containers in the widget tree with explicit ownership and typed BuildContext access.

v1.1.0Beginnerark_di_flutter

Flutter integration

ark_di_flutter adapts an existing DiContainer to Flutter. It does not add registrations at runtime or move construction into widgets.

The ownership model

text
Bootstrap creates application DiContainer
        ↓
DiRootScope exposes that container to the widget tree
        ↓
DiScope creates a child container for a bounded subtree
        ↓
BuildContext resolves the nearest Scope
        ↓
removing the subtree closes owned child dependencies

The widget tree supplies lifetime boundaries; the core container still supplies registration, resolution, cycle detection, and teardown semantics.

  • DiRootScope exposes an application container.
  • DiScope creates and owns a child container.
  • DiBuildContextExtension provides subscribed and one-off access.
  • service_locator.dart is a separate opt-in compatibility library.

Choose an entry point

NeedStart with
One application container and one feature ScopeScope a Flutter application tutorial
Ownership and replacement rulesRoot and child Scope
Rebuild when the nearest container changescontext.di in BuildContext access
One-off lookup in an event callbackcontext.readDi in BuildContext access
Legacy API requires locator semanticsOpt-in Service Locator after reviewing its limits

Do not use BuildContext from domain objects or store a child DiContainer globally. Resolve at the widget or feature composition boundary, then pass ordinary constructor arguments to the objects below it.