1

I use this answer in my solution.

In order to implement dragging picture on an enlarged scale.

But in the original version, there was no increase in the picture using double-tap.

And I tried to make it myself. And it seems to me, something happened.

Here is my code:

class ZoomableWidget extends StatefulWidget {
  final Widget child;

  const ZoomableWidget({Key key, this.child}) : super(key: key);
  @override
  _ZoomableWidgetState createState() => _ZoomableWidgetState();
}

class _ZoomableWidgetState extends State<ZoomableWidget> {
  Matrix4 matrix = Matrix4.identity();
  Matrix4 zerada =  Matrix4.identity();
  bool zoomed = false;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onDoubleTap: (){

        matrix.scale(!zoomed ? 2.0 : 1.0);
        zoomed = !zoomed;
        if (!zoomed) matrix = Matrix4.identity();
        setState(() {
          matrix = matrix;
        });
      },
      child: MatrixGestureDetector(
        shouldRotate: false,
        shouldScale: true,
        onMatrixUpdate: (Matrix4 m, Matrix4 tm, Matrix4 sm, Matrix4 rm) {
          setState(() {
            matrix = zoomed ? m : matrix;
          });
        },
        child: Transform(
          transform: matrix,
          child: widget.child,
        ),
      ),
    );
  }
}

But immediately after the picture increased, she drove down. And when I start dragging image, the zoom is reset to the default value. Please tell me what should I do to fix my problem?

enter image description here

MadLax
  • 1,149
  • 3
  • 10
  • 13
  • 1
    if your matrix is changed by your code then use the same pattern like here: https://github.com/pskink/matrix_gesture_detector/blob/master/example/lib/transform_demo2.dart#L40 – pskink Jan 10 '20 at 18:59
  • @pskink, yes thank you! This is exactly what I was missing. – MadLax Jan 11 '20 at 13:29

0 Answers0