Flutter : IgnorePointer with InteractiveViewer

Dr_Skele·2023년 4월 18일
0

Flutter

목록 보기
19/19

As I develop a image editing tool for profile image, I faced a problem with overlapped widgets.

To edit the image, the user should be able to zoom out or in, and drag the image around. This can be done by using InteractiveViewer, but then the widget covering InteractiveViewer, which blurs out other part of the image that's not used for profile, prevents interacting with it.

Stack(
          fit: StackFit.expand,
          children: [
            InteractiveViewer(
              constrained: false,
              child: Image.file(
                File(context.watch<SelectedImage>().file.path),
                colorBlendMode: BlendMode.dstOut,
              ),
            ),
            CustomPaint(
                painter: CameraPainter(),
            ),
          ],
        )

The top most widget, in this case, the CustomPaint widget consumes user interaction making the InteractiveViewer useless.
Problem here is simple. User interaction just need to reach the InteractiveViewer below.

Stack(
          fit: StackFit.expand,
          children: [
            InteractiveViewer(
              constrained: false,
              child: Image.file(
                File(context.watch<SelectedImage>().file.path),
                colorBlendMode: BlendMode.dstOut,
              ),
            ),
            IgnorePointer(
              child: CustomPaint(
                painter: CameraPainter(),
              ),
            )
          ],
        )

Just wrapping the blocking widget with IgnorePointer solves the problem. IgnorePointer doesn't simply remove the user input, but it literally ignores it without consuming it. Therefore, the widget stacked below can use the user input passing through the IgnorePointer widget.

profile
Tireless And Restless Debugging In Source : TARDIS

0개의 댓글