paint method Null safety

  1. @override
void paint(
  1. PaintingContext context,
  2. Offset center,
  3. {required Animation<double> activationAnimation,
  4. required Animation<double> enableAnimation,
  5. required bool isDiscrete,
  6. required TextPainter labelPainter,
  7. required RenderBox parentBox,
  8. required SliderThemeData sliderTheme,
  9. required TextDirection textDirection,
  10. required double value,
  11. required double textScaleFactor,
  12. required Size sizeWithOverflow}

Paints the shape, taking into account the state passed to it.

The context argument is the same as the one that includes the Slider's render box.

The center argument is the offset for where this shape's center should be painted. This offset is relative to the origin of the context canvas.

The activationAnimation argument is an animation triggered when the user begins to interact with the slider. It reverses when the user stops interacting with the slider.

The enableAnimation argument is an animation triggered when the Slider is enabled, and it reverses when the slider is disabled. The Slider is enabled when Slider.onChanged is not null.Use this to paint intermediate frames for this shape when the slider changes enabled state.

The isDiscrete argument is true if Slider.divisions is non-null. When true, the slider will render tick marks on top of the track.

If the labelPainter argument is non-null, then TextPainter.paint should be called on the labelPainter with the location that the label should appear. If the labelPainter argument is null, then no label was supplied to the Slider.

The parentBox argument is the RenderBox of the Slider. Its attributes, such as size, can be used to assist in painting this shape.

the sliderTheme argument is the theme assigned to the Slider that this shape belongs to.

The textDirection argument can be used to determine how any extra text or graphics (besides the text painted by the labelPainter) should be positioned. The labelPainter already has the textDirection set.

The value argument is the current parametric value (from 0.0 to 1.0) of the slider.

The textScaleFactor argument can be used to determine whether the component should paint larger or smaller, depending on whether textScaleFactor is greater than 1 for larger, and between 0 and 1 for smaller. It usually comes from MediaQueryData.textScaleFactor.

The sizeWithOverflow argument can be used to determine the bounds the drawing of the components that are outside of the regular slider bounds. It's the size of the box, whose center is aligned with the slider's bounds, that the value indicators must be drawn within. Typically, it is bigger than the slider.


void paint(
  PaintingContext context,
  Offset center, {
  required Animation<double> activationAnimation,
  required Animation<double> enableAnimation,
  required bool isDiscrete,
  required TextPainter labelPainter,
  required RenderBox parentBox,
  required SliderThemeData sliderTheme,
  required TextDirection textDirection,
  required double value,
  required double textScaleFactor,
  required Size sizeWithOverflow,
}) {
  assert(context != null);
  assert(center != null);
  assert(activationAnimation != null);
  assert(enableAnimation != null);
  assert(labelPainter != null);
  assert(parentBox != null);
  assert(sliderTheme != null);
  assert(textDirection != null);
  assert(value != null);

  final Canvas canvas = context.canvas;
  final Tween<double> radiusTween = Tween<double>(
    begin: 0.0,
    end: overlayRadius,

    Paint()..color = sliderTheme.overlayColor!,