SignalCustomPainter class abstract

A premium custom painter that automatically repaints when any observed signal changes, bypassing Flutter's widget build and layout phases completely.

SignalCustomPainter registers subscriptions to the provided list of signals. When any of these signals fire, a GPU repaint is scheduled directly via markNeedsPaint(), bypassing the widget-tree build cycle and layout passes for unmatched graphics performance.

Canvas Particle/Graph Example

final cursorOffset = signal(const Offset(0, 0));

class StarField extends StatelessWidget {
  const StarField({super.key});

  @override
  Widget build(BuildContext context) {
    return SignalCustomPaint(
      painter: StarPainter(cursorOffset),
      child: const SizedBox.expand(),
    );
  }
}

class StarPainter extends SignalCustomPainter {
  StarPainter(this.offsetSignal) : super(signals: [offsetSignal]);

  final ReadonlySignal<Offset> offsetSignal;

  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint()..color = Colors.amber;
    // Access the signal's value to paint.
    // Note: Signal tracking is suspended during paint, so .value or .peek() are both safe!
    canvas.drawCircle(offsetSignal.value, 15.0, paint);
  }

  @override
  bool shouldRepaint(covariant StarPainter oldDelegate) => true;
}

Constructors

SignalCustomPainter({required List<ReadonlySignal> signals})
Creates a new SignalCustomPainter.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
signals List<ReadonlySignal>
The list of signals to observe for changes.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
paint(Canvas canvas, Size size) → void
Paint on the canvas.
shouldRepaint(covariant SignalCustomPainter oldDelegate) bool
Return true if the painter should be updated when the widget configuration changes.
toString() String
A string representation of this object.
inherited

Operators

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