State<T>

Abstract Class
The state of a StatefulWidget. It holds its widget's internal state and is used to update the UI when the widget configuration changes.

Once the state is created, a call to InitState will be made immediately before the first Build call.

The state maintains a list of managed disposables that will be disposed when the state is disposed and also provides a Dispose callback method.

Signal values can be directly accessed from within the state's Build methods and dependencies will be automatically tracked by the SignalDependencyTracker.

Once any dependency changes or SetState gets called, a ModificationBarrier.Rebuild will be scheduled. Once the Reconciler rebuilds the object, CanReconcile will be called to determine if the state can be reused with the new widget configuration. If it returns true, DidUpdateWidget will be called to notify the state of the new widget configuration before the Build method is called again.

Fields

dependencyTracker: SignalDependencyTracker
The SignalDependencyTracker that tracks signal dependencies for this state.
The IWidgetElement that this state is mounted to. This context will never change and can be used to access the VisualElement of the widget. Will also always be equal to the context passed into the Build method.
widget: T
The widget configuration that is currently bound to this state.

Methods

AddDisposable<S>(disposable: S): S
Tracks a disposable dependency that will automatically be disposed when the state is disposed.
RemoveDisposable<S>(disposable: S): void
Removes a disposable dependency from the state's managed disposables.
SetState(): void
Schedules a rebuild of the widget.
SetState(action: Action): Action
Wraps an action in a tailing SetState call.
DebugFillProperties(properties: DiagnosticPropertiesBuilder): void
CanReconcile(oldWidget: T): bool
Called when the state is about to be rebuilt with a new widget configuration.

Parameters

oldWidget:T - The widget configuration before the rebuild. The current widget configuration is available through the widget property.

Returns

bool-Whether the state can be reused with the new widget configuration.
DidUpdateWidget(oldWidget: T): void
Called when the state is rebuilt with a new widget configuration.

Parameters

oldWidget:T - The widget configuration before the rebuild. The current widget configuration is available through the widget property.
Dispose(): void
InitState(): void
Called immediately before the first Build call to initialize the state.
RemarksSubscriptions and disposables should be created here and then properly disposed in Dispose if not automatically disposed using AddDisposable.
Build(context: BuildContext): Widget
Builds the widget in the given context.

Parameters

context:BuildContext - The context in which to build the widget. This will be provided by the framework when building the widget tree.

Inherited Members

Extension Methods

ToDiagnosticsNodeSafeDescribeIdentityShortHashToStringNullable

On this page