HighlighterPainter class

A CustomPainter that creates an animated highlight effect behind text.

Supports two modes:

  • Organic Mode: Wavy, hand-drawn highlight.
  • Plain Mode: Straight, structured highlight.

This effect mimics the look of someone marking text with a highlighter.

Example Usage:

CustomPaint(
  painter: HighlighterPainter(
    text: "Flutter",
    textStyle: TextStyle(fontSize: 24, color: Colors.black),
    highlightColor: Colors.yellow,
    animationValue: 1.0,  // 100% completed highlight
    animationMode: SketchyAnimationMode.organic, // or SketchyAnimationMode.plain
    precomputedOffsets: List.generate(1000, (index) => Random().nextDouble()),
  ),
  child: Text("Flutter", style: TextStyle(fontSize: 24, color: Colors.black)),
)
Inheritance

Constructors

HighlighterPainter({required String text, required TextStyle textStyle, required Color highlightColor, required double animationValue, required List<double> precomputedOffsets, SketchyAnimationMode animationMode = SketchyAnimationMode.organic})
Creates a HighlighterPainter to draw an animated highlight behind text.

Properties

animationMode SketchyAnimationMode
Determines whether the highlight should be sketchy (organic) or straight (plain).
final
animationValue double
Controls the animation progress (0 to 1).
final
hashCode int
The hash code for this object.
no setterinherited
highlightColor Color
The color of the animated highlight.
final
precomputedOffsets List<double>
A list of random offsets to create an organic, hand-drawn effect.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
semanticsBuilder SemanticsBuilderCallback?
Returns a function that builds semantic information for the picture drawn by this painter.
no setterinherited
text String
The text to be highlighted.
final
textStyle TextStyle
The text style used for measuring dimensions.
final

Methods

addListener(VoidCallback listener) → void
Register a closure to be notified when it is time to repaint.
inherited
hitTest(Offset position) bool?
Called whenever a hit test is being performed on an object that is using this custom paint delegate.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
paint(Canvas canvas, Size size) → void
Called whenever the object needs to paint. The given Canvas has its coordinate space configured such that the origin is at the top left of the box. The area of the box is the size of the size argument.
override
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that the object notifies when it is time to repaint.
inherited
shouldRebuildSemantics(covariant CustomPainter oldDelegate) bool
Called whenever a new instance of the custom painter delegate class is provided to the RenderCustomPaint object, or any time that a new CustomPaint object is created with a new instance of the custom painter delegate class (which amounts to the same thing, because the latter is implemented in terms of the former).
inherited
shouldRepaint(covariant CustomPainter oldDelegate) bool
Called whenever a new instance of the custom painter delegate class is provided to the RenderCustomPaint object, or any time that a new CustomPaint object is created with a new instance of the custom painter delegate class (which amounts to the same thing, because the latter is implemented in terms of the former).
override
toString() String
A string representation of this object.
inherited

Operators

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