Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter InteractiveViewer with CustomPaint

Tags:

flutter

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;
  }
}
like image 211
Develocode 777 Avatar asked Oct 20 '25 08:10

Develocode 777


1 Answers

Try to contain your CustomPaint in RepaintBoundary

For example

return InteractiveViewer(
  maxScale: 6,
  minScale: 0.3,
  child: CustomPaint(
    size: Size.infinite,
    painter: MapPainter(snapshot.data),
    child: RepaintBoundary(
          child: CustomPaint(
            size: Size.infinite,
            painter: DeskPainter(desk),
          ),
        ),
  ),
);
like image 195
Oliinyk Artemii Avatar answered Oct 21 '25 22:10

Oliinyk Artemii