【发布时间】:2018-08-14 09:20:19
【问题描述】:
我正在尝试读取文件(异步)并返回数据列表。然后,我想在每个给定数字都是线高时使用 CustomPainter 画线(我想画多条线)
class BarChartPainter extends CustomPainter {
@override
paint(Canvas canvas, Size size) {
final paint = new Paint()
..color = AppColors.primaryColor
..style = PaintingStyle.fill;
var futurePath = run();
futurePath.then((height) {
print('1: $height');
for (var lineHeight in height) {
print('2: $lineHeight');
canvas.drawRect(
new Rect.fromLTWH(1.0, 10.0, 10.0, lineHeight.toDouble()), paint);
}
}).catchError((e) => print(e));
}
@override
bool shouldRepaint(BarChartPainter old) => false;
}
print('1: $height') 返回 [75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 86, 72, 10, 2, 0, 0, 0, 0, 0, (...), 0, 85, 22, 3, 1]
print('2: $lineHeight') 返回 75
drawRect 不起作用。错误是:I/flutter (13751):对象已被释放。
【问题讨论】: