Tutorials
Scope a Flutter application
Attach an application container, create a feature Scope, and resolve dependencies through BuildContext.
v0.1.0-dev.1Intermediateark_di_flutter
Scope a Flutter application
Create the application container before runApp, then attach it:
dart
DiRootScope(
container: application,
child: const App(),
)
Create a feature Scope inside the widget tree:
dart
DiScope(
configure: (binder) {
binder.bindFactory<FeaturePresenter>(
(resolver) => FeaturePresenter(resolver.get<CatalogRepository>()),
);
},
child: const FeatureScreen(),
)
Use context.di from build or didChangeDependencies when the code must follow Scope replacement. Use context.readDi for one-off callback reads. The widget that owns a container closes it when its ownership ends.