When scaling and moving with the InteractiveViewer
the paint
method inside CustomPaint
is triggered. How to prevent that?
...
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;
}
}
Try to contain your CustomPaint in RepaintBoundary
For example
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,
),
),
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.