Flutter Zoomable Widget

后端 未结 5 665
后悔当初
后悔当初 2020-11-30 09:28

What I want to build is a widget that can make its child widget zoomable similar to the zoomable behavior.

Gestures I want to cover are

  1. Pinch To Zoom
5条回答
  •  粉色の甜心
    2020-11-30 09:59

    This is working perfectly now, thanks for the reference @pskink.

    import 'package:flutter/material.dart';
    import 'package:matrix_gesture_detector/matrix_gesture_detector.dart';
    
    class ZoomableWidget extends StatefulWidget {
      final Widget child;
    
      const ZoomableWidget({Key key, this.child}) : super(key: key);
      @override
      _ZoomableWidgetState createState() => _ZoomableWidgetState();
    }
    
    class _ZoomableWidgetState extends State {
      Matrix4 matrix = Matrix4.identity();
    
      @override
      Widget build(BuildContext context) {
        return MatrixGestureDetector(
          onMatrixUpdate: (Matrix4 m, Matrix4 tm, Matrix4 sm, Matrix4 rm) {
            setState(() {
              matrix = m;
            });
          },
          child: Transform(
            transform: matrix,
            child: widget.child,
          ),
        );
      }
    }
    

提交回复
热议问题