使用InteractiveViewer
缩放和移动时,将触发paint
内部的CustomPaint
方法。如何预防呢?
...
InteractiveViewer(
child: CustomPaint(
painter: TestPainter(),
),
),
...
class TestPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
print('painting...');
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}
答案 0 :(得分:0)
尝试在 RepaintBoundary 中包含您的 CustomPaint
例如
final List<Widget> desks = _mapDataState.mapObjects.desks
.map((desk) => RepaintBoundary(
child: CustomPaint(
size: Size.infinite,
painter: DeskPainter(desk),
),
))
.toList();
return InteractiveViewer(
maxScale: 6,
minScale: 0.3,
child: CustomPaint(
size: Size.infinite,
painter: MapPainter(snapshot.data),
child: Stack(
children: desks,
),
),
);