BloomContext<T> class
Token representing an ambient context value of type T.
Context allows passing data down through a subtree without manually threading properties through every intermediate component ("prop drilling"). A context is created via createContext, injected into a subtree via provide, and consumed inside descendant components via useContext.
Zone-Based Propagation and Limitations
Context values are propagated through Dart Zone values captured during synchronous tree mounting and SSR rendering.
Important Gotcha: When a reactive boundary (such as Live or Show)
rebuilds in response to a signal update, its builder callback executes in
the Zone captured when that reactive effect was originally mounted. If an
ancestor provider dynamically changes the value it supplies, descendant
reactive rebuilds will continue to read the value from their initial mount zone
unless the provider itself triggers a rebuild of the entire subtree. For dynamic
state that changes over time, use Signal<T> instead of relying on mutable context.
final themeContext = createContext('light');
BloomNode themedCard() {
final theme = useContext(themeContext);
return Div(
className: 'card card-$theme',
text: 'Current theme: $theme',
);
}
BloomNode app() => themeContext.provide(
'dark',
Div(
children: [
themedCard(),
],
),
);
Constructors
- BloomContext(T defaultValue)
-
Creates a new ambient BloomContext token with the specified
defaultValue.
Properties
- defaultValue → T
-
The fallback value returned by useContext when no matching provider
exists in the ancestor hierarchy.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- zoneKey → Object
-
The unique key used to look up and store this context's value within
the ambient Zone.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
provide(
T value, BloomNode child) → BloomNode -
Provides
valueto all children in thechildsubtree. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited