SetupWidget class abstract

A base widget class that supports reactive setup and lifecycle hooks.

SetupWidget provides a declarative way to create reactive components that automatically track dependencies and update when those dependencies change.

Subclass SetupWidget to create a reusable widget component with:

  • Reactive state management via setup method
  • Lifecycle hooks for mount/unmount/update events
  • Dependency injection via widget refs
  • Automatic cleanup and dependency tracking

The setup widget lifecycle:

  1. Widget is created and createElement is called
  2. setup is invoked to initialize component logic and state
  3. Component is mounted and begins tracking dependencies
  4. Dependencies update triggers reactive re-rendering
  5. Widget unmounts and cleanup runs automatically

Example:

class MyWidget extends SetupWidget {
  @override
  Widget Function() setup() {
    // Initialize reactive state and effects here
    return () => Text('Hello');
  }
}
Inheritance
Implementers

Constructors

SetupWidget({Key? key, WidgetRef<SetupWidget>? ref})
Creates a SetupWidget with an optional key and ref.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() SetupElement
Inflates this configuration to a concrete instance.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setup() Widget Function()
The main setup function that defines the widget's build logic.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited