AppInstance constructor
AppInstance(
- App component
Creates an application instance for the given root App component.
The constructor initializes the application instance and performs the initial build of the component tree. It also sets this instance as the global singleton accessible via AppInstance.instance.
Parameters:
component
: The root App component that defines the application's structure and behavior. This component serves as the entry point for the entire component hierarchy.
Initialization process:
- Creates empty initial state for child instances
- Sets this instance as the global singleton
- Builds the initial component tree by creating instances for all children of the root component
- Stores both the current and initial children for reference
Example:
final app = App(children: [Header(), Content(), Footer()]);
final appInstance = AppInstance(app);
Throws:
- May throw if the component tree cannot be built properly
See also:
- AppInstance.instance to access the singleton instance
- App.createInstance for the component instance creation mechanism
Implementation
AppInstance(this.component)
: _childrenInstance = [],
initialChildren = [],
super(component) {
// Make this the global singleton instance.
AppInstance.instance = this;
// Build the initial child component instances.
final created = component.children
.map((Component comp) => comp.createInstance())
.toList();
_childrenInstance = created;
initialChildren = List.from(created);
}