Ref<T extends Object> class
Reference holder for imperative access to mounted DOM elements.
Created before mounting and passed to a RefNode or component with ref support. The browser mount engine automatically populates value when the DOM element is created and attached, and resets it when unmounted.
SSR Behavior
In SSR (renderToHtml), refs remain unpopulated and isMounted returns false.
Attempting to read value during SSR will throw a StateError.
final inputRef = Ref<Object>();
BloomNode searchBox() => Mount(
RefNode(
inputRef,
Input(placeholder: 'Search documentation...'),
),
onMount: () {
// Focus element when mounted in the browser
if (inputRef.isMounted) {
// Interop or custom logic with inputRef.value
}
},
);
Constructors
- Ref()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isMounted → bool
-
Whether this ref currently holds an active, mounted DOM element.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → T
-
The mounted DOM element instance.
no setter
Methods
-
attach(
T element) → void -
Attaches
elementto this ref. -
detach(
) → void - Detaches the element and resets this ref to unmounted state.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited