Documentation Index
Fetch the complete documentation index at: https://mintlify.com/khode-io/nest-dart/llms.txt
Use this file to discover all available pages before exploring further.
Overview
ModularApp is the root widget that initializes the dependency injection container and module system. It must wrap your application’s root widget to enable the use of Modular static methods and dependency injection throughout your widget tree.
Constructor
Properties
The root module of your application. This module and all its imports will be registered in the dependency injection container.
The root widget of your application, typically a
MaterialApp or CupertinoApp.Optional custom container instance. If not provided, a new container will be created automatically.
This is useful for testing or when you need to provide a pre-configured container.
Custom loading widget to display during container initialization. If not provided, a default loading screen with
CircularProgressIndicator will be shown.Initialization Flow
TheModularApp widget follows this initialization sequence:
- Create Container: Creates or uses the provided
ApplicationContainer - Store Root Module: Saves the root module reference for router configuration
- Register Module: Asynchronously registers the module and all its dependencies
- Create Notifier: Wraps the container in an
ApplicationContainerNotifier - Set Global Container: Makes the container available via
Modularstatic methods - Provide to Tree: Provides the container to the widget tree via
InheritedWidget
Usage Example
Basic Setup
With Custom Loading Screen
With Custom Container (Testing)
Lifecycle Management
TheModularApp widget manages the container lifecycle automatically:
- initState: Initializes the container and registers modules
- didChangeDependencies: Re-establishes global container reference
- dispose: Clears global container and disposes notifier
The global container is automatically cleared when
ModularApp is disposed, preventing memory leaks.Error Handling
See Also
- Modular Class - Static methods for dependency injection
- Module Class - Creating modules with routes
- Routing - Route collection and GoRouter integration