Flutter Paint Canvas - Draw a line with gradient running from side of line to the other, not end to end

304 Views Asked by At

enter image description here

I have the x,y for both ends of this line on a canvas, how do I run a gradient from the line sides(as pic).

import 'dart:ui' as ui;
canvas.drawLine(
        Offset(x,
            y),
        Offset(x,
            y),
        Paint()
          ..style = PaintingStyle.stroke
          ..strokeWidth = 4.0
          ..shader = ui.Gradient.linear( // What do I use here? 
          startOffset,
          endOffset,
         [
         color1,
         color2,
         ],
         ),); 
0

There are 0 best solutions below