modularity_flutter#
Flutter integration for the Modularity dependency injection framework.
Provides widgets that manage Module lifecycles within the Flutter widget tree, including automatic initialization, error handling, and configurable retention policies.
Getting Started#
Wrap your app with ModularityRoot and place ModuleScope widgets where modules are needed:
final observer = RouteObserver<ModalRoute<dynamic>>();
ModularityRoot(
observer: observer,
child: MaterialApp(
navigatorObservers: [observer],
home: ModuleScope<HomeModule>(
module: HomeModule(),
child: const HomePage(),
),
),
)
Access registered dependencies via ModuleProvider:
final service = ModuleProvider.of(context).get<MyService>();
Key Classes#
- ModularityRoot -- root widget providing DI configuration, observer, interceptors, and lifecycle logging.
- ModuleScope -- manages a single module's lifecycle with retention.
- ModuleProvider -- exposes a module's Binder to descendants.
- ModuleRetainer -- cache for controllers with KeepAlive policy.
Classes#
| Class | Description |
|---|---|
| ModularityRoot | Root widget for the Modularity framework. |
| ModuleProvider | Inherited widget that exposes a ModuleController and its Binder to descendant widgets. |
| ModuleRetainer | Cache for ModuleController instances with KeepAlive retention policy. |
| ModuleRetainerEntrySnapshot | Snapshot of a retained module entry for debugging purposes. |
| ModuleScope<T extends dynamic> | Widget that manages the lifecycle of a Module and exposes its DI container. |
Enums#
| Enum | Description |
|---|---|
| ModuleLifecycleEvent | Lifecycle event types emitted by the retention and scope systems. |
Typedefs#
| Typedef | Description |
|---|---|
| ModuleLifecycleLogger | Callback signature for module lifecycle logging. |