Flutter Zoomable Widget

后端 未结 5 670
后悔当初
后悔当初 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:40

    As of Flutter 1.20, InteractiveViewer widget supports pan and Zoom out of the box.
    To make any widget zoomable you need to simply wrap the child with InteractiveViewer.

    @override
    Widget build(BuildContext context) {
      return Center(
        child: InteractiveViewer(
          panEnabled: false, // Set it to false to prevent panning. 
          boundaryMargin: EdgeInsets.all(80),
          minScale: 0.5,
          maxScale: 4, 
          child: FlutterLogo(size: 200),
        ),
      );
    }
    

提交回复
热议问题