Skip to content
modularity_flutterClassesmodularity_flutter

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:

dart
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:

dart
final service = ModuleProvider.of(context).get<MyService>();

Key Classes

Classes

ClassDescription
ModularityRootRoot widget for the Modularity framework.
ModuleProviderInherited widget that exposes a ModuleController and its Binder to descendant widgets.
ModuleRetainerCache for ModuleController instances with KeepAlive retention policy.
ModuleRetainerEntrySnapshotSnapshot 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

EnumDescription
ModuleLifecycleEventLifecycle event types emitted by the retention and scope systems.

Typedefs

TypedefDescription
ModuleLifecycleLoggerCallback signature for module lifecycle logging.