fillTopDownGradient method

  1. @override
void fillTopDownGradient(
  1. num x,
  2. num y,
  3. num width,
  4. num height,
  5. PColor colorFrom,
  6. PColor colorTo,
)
override

Fill a rectangle (x,y , width x height) with a top down linear gradient. See fillBottomUpGradient.

Implementation

@override
void fillTopDownGradient(
    num x, num y, num width, num height, PColor colorFrom, PColor colorTo) {
  var xd = transform.xD(x);
  var yd = transform.yD(y);

  xd = canvasXD(xd);
  yd = canvasYD(yd);

  final widthD = canvasXD(width);
  final heightD = canvasYD(height);

  final rect = Rect.fromLTWH(xd, yd, widthD, heightD);

  final paint = Paint()
    ..shader = ui.Gradient.linear(
      Offset(xd, yd),
      Offset(xd, (yd + heightD)),
      [colorFrom.asColor, colorTo.asColor],
    );

  _widgetPainter.addOp((canvas, size) {
    canvas.drawRect(rect, paint);
  });
}