Slot<T> class
============================================================================ 4. SLOT WIDGETS (BINDING SIGNALS TO UI)
Connects a ValueListenable (signal) to the UI and rebuilds when it changes.
Slot is the primary widget for binding signals to UI in Neuron. It uses ValueListenableBuilder internally for efficient, granular rebuilds.
Basic Usage
Slot<int>(
connect: controller.count,
to: (context, value) => Text('Count: $value'),
)
Multiple Signals
To listen to multiple signals, nest Slot widgets:
Slot<int>(
connect: controller.count,
to: (ctx, count) => Slot<String>(
connect: controller.name,
to: (ctx, name) => Text('$name: $count'),
),
)
With Static Children
Use the child parameter to avoid rebuilding static widgets:
Slot<int>(
connect: controller.count,
to: (ctx, val) => Column(
children: [Text('Count: $val'), child!],
),
child: ElevatedButton(
onPressed: () {},
child: Text('Static Button'),
),
)
Performance: Only the widget returned by to is rebuilt when the signal changes. Sibling widgets are not affected.
See also:
- AsyncSlot - For async signals with loading/error states
- Signal - Basic reactive value
- Computed - Derived values A widget that rebuilds when a Signal or Computed changes.
This is the primary widget for binding signals to the UI.
Basic Usage
final count = Signal(0);
Slot(
connect: count,
to: (context, value) => Text('Count: $value'),
)
With Computed Signals
final count = Signal(0);
final doubleCount = Computed(() => count.value * 2);
Slot(
connect: doubleCount,
to: (context, value) => Text('Double: $value'),
)
- Inheritance
- Available extensions
Constructors
-
Slot({Key? key, required NeuronAtom<
T> connect, required Widget to(BuildContext context, T value), Widget? child}) -
const
Properties
- child → Widget?
-
Optional child widget for optimization (not currently used in builder, but good practice).
final
-
connect
→ NeuronAtom<
T> -
The signal to listen to.
final
- 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
- to → Widget Function(BuildContext context, T value)
-
The builder function.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< Slot< T> > -
Creates the mutable state for this widget at a given location in the tree.
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
-
onTap(
VoidCallback onTap, {double pressedScale = 0.95}) → Widget -
Available on Widget, provided by the SlotWidgetModifiers extension
Wrap with tap gesture. -
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
-
withDelay(
Duration delay) → Widget -
Available on Widget, provided by the SlotWidgetModifiers extension
Add a delay before showing. -
withFade(
{Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeInOut}) → Widget -
Available on Widget, provided by the SlotWidgetModifiers extension
Wrap with fade animation on appear. -
withHero(
Object tag) → Widget -
Available on Widget, provided by the SlotWidgetModifiers extension
Wrap with hero animation. -
withScale(
{double begin = 0.8, double end = 1.0, Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeOutBack}) → Widget -
Available on Widget, provided by the SlotWidgetModifiers extension
Wrap with scale animation on appear. -
withShimmer(
{Duration duration = const Duration(milliseconds: 1500), Color baseColor = const Color(0xFFE0E0E0), Color highlightColor = const Color(0xFFF5F5F5)}) → Widget -
Available on Widget, provided by the SlotWidgetModifiers extension
Apply a shimmer loading effect. -
withSlide(
{Offset begin = const Offset(0, 0.2), Offset end = Offset.zero, Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeOutCubic}) → Widget -
Available on Widget, provided by the SlotWidgetModifiers extension
Wrap with slide animation on appear.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited