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.
DiRootScopeexposes an application container.DiScopecreates and owns a child container.DiBuildContextExtensionprovides subscribed and one-off access.service_locator.dartis a separate opt-in compatibility library.
Choose an entry point
| Need | Start with |
|---|---|
| One application container and one feature Scope | Scope a Flutter application tutorial |
| Ownership and replacement rules | Root and child Scope |
| Rebuild when the nearest container changes | context.di in BuildContext access |
| One-off lookup in an event callback | context.readDi in BuildContext access |
| Legacy API requires locator semantics | Opt-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.