BuildContextExtension extension

Provides convenience methods on BuildContext to retrieve, manage, and react to application-wide services and state.

on

Methods

serviceFor<T extends Service>({Key? key, ServiceMode mode = .watch}) → T

Available on BuildContext, provided by the BuildContextExtension extension

Retrieves an existing service by type and optional key. Throws a StateError if no matching service is registered.
serviceOf<T extends Service>(T create(), {Key? key, ServiceMode mode = .watch}) → T

Available on BuildContext, provided by the BuildContextExtension extension

Retrieves or lazily creates a service of type T, and binds its lifecycle to this BuildContext's widget lifecycle.
sharedStateFor<T>({required Key key, StateMode mode = .watch}) → ValueState<T>

Available on BuildContext, provided by the BuildContextExtension extension

Retrieves existing shared state by type and key within the same StateScope. Throws a StateError if no matching shared state is registered.
sharedStateOf<T>(T create(), {required Key key, StateMode mode = .watch, dynamic onDispose(T)?}) → ValueState<T>

Available on BuildContext, provided by the BuildContextExtension extension

Retrieves or lazily creates state shared by key across elements under the same StateScope.
stateFor<T>({required Key key, StateMode mode = .watch}) → ValueState<T>

Available on BuildContext, provided by the BuildContextExtension extension

Retrieves existing state owned by this element by type and key. Throws a StateError if no matching state is registered.
stateOf<T>(T create(), {Key? key, StateMode mode = .watch, dynamic onDispose(T)?}) → ValueState<T>

Available on BuildContext, provided by the BuildContextExtension extension

Retrieves or lazily creates a state of type T, and binds its ValueState lifecycle to this BuildContext's widget lifecycle.