使用canvas.drawVertices更改顶点和线条的颜色

时间:2020-02-07 20:25:05

标签: flutter canvas

常规Paint对象似乎并没有改变使用drawVertices绘制的线条的外观。这是我尝试过的。

// Doesn't do anything
var brush = Paint()..color = Colors.blue..strokeWidth = 4..style = PaintingStyle.stroke;

// The only shaders I've found are UI.Gradient and UI.ImageShader
brush = brush..shader = UI.Gradient.linear(
  Offset(0, 0),
  // absurd numbers
  Offset(10000, 10000),
  [Colors.blue, Colors.blue],
);

canvas.drawVertices(
  UI.Vertices.raw(
    VertexMode.triangleStrip,
    storage,
    // This will change the colors of the faces not the lines
    // colors: _encodeColorList(storageCount.map((_) => Colors.white).toList())
  ),
  BlendMode.dstIn,
  brush,
);


// Copied from dart:ui
Int32List _encodeColorList(List<Color> colors) {
  final int colorCount = colors.length;
  final Int32List result = Int32List(colorCount);
  for (int i = 0; i < colorCount; ++i) result[i] = colors[i].value;

  return result;
}

线条颜色始终为黑色:

enter image description here

编辑:

这可能是框架错误。这是Github issue for reference

0 个答案:

没有答案
相关问题