ReactiveWidget class abstract

A StatefulWidget with reactive State that supports custom Flutter mixins.

Create a custom State class where you can add Flutter's built-in mixins like SingleTickerProviderStateMixin.

Example with animation:

class AnimatedCounter extends ReactiveWidget {
  const AnimatedCounter({super.key});

  @override
  ReactiveState<AnimatedCounter> createState() => _AnimatedCounterState();
}

class _AnimatedCounterState extends ReactiveState<AnimatedCounter>
    with SingleTickerProviderStateMixin {
  late final controller = AnimationController(
    vsync: this,
    duration: const Duration(milliseconds: 300),
  );
  late final count = ref(0);

  @override
  void setup() {
    onMounted(() => controller.forward();
    onDispose(() => controller.dispose();
  }

  @override
  Widget render(BuildContext context) {
    return FadeTransition(
      opacity: controller,
      child: Text('Count: ${count.value}'),
    );
  }
}

Example with keep alive:

class KeepAliveCounter extends ReactiveWidget {
  const KeepAliveCounter({super.key});

  @override
  ReactiveState<KeepAliveCounter> createState() => _KeepAliveCounterState();
}

class _KeepAliveCounterState extends ReactiveState<KeepAliveCounter>
    with AutomaticKeepAliveClientMixin {
  late final count = ref(0);

  @override
  bool get wantKeepAlive => true;

  @override
  void setup() {}

  @override
  Widget build(BuildContext context) {
    super.build(context); // Required for AutomaticKeepAliveClientMixin
    return reactiveBuild(context); // Use reactiveBuild() instead of duplicating logic
  }

  @override
  Widget render(BuildContext context) {
    return Text('Count: ${count.value}');
  }
}
Inheritance

Constructors

ReactiveWidget({Key? key})
Creates a reactive stateful widget.
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() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() ReactiveState<ReactiveWidget>
Override this to create your custom ReactiveState subclass.
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
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