可缩放和可拖动的独立图形

时间:2019-02-20 22:47:49

标签: dart flutter flutter-layout

我正在尝试实现使两个圆圈同时缩放的方法,但也可以独立拖动它们。

我已经实现了一些添加圆的功能以及缩放功能,但是拖动功能是我的问题。

我是初学者。

这是我的代码:

https://github.com/SantyTaco/flutter_app_zoom_example

代码的主要部分是这样的:

void _handleScaleStart(ScaleStartDetails details) {
setState(() {
  _startingFocalPoint = details.focalPoint;
  _previousOffset = _offset;
  _previousZoom = _zoom;
});
}



void _handleScaleUpdate(ScaleUpdateDetails details) {
    setState(() {
      _zoom = _previousZoom * details.scale;

      // Ensure that item under the focal point stays in the same place despite zooming
      final Offset normalizedOffset = (_startingFocalPoint - _previousOffset) / _previousZoom;
      _offset = details.focalPoint - normalizedOffset * _zoom;
    });
  }





@override
  Widget build(BuildContext context) {
    return Stack(
        fit: StackFit.expand,
        children: <Widget>[
          GestureDetector(
              onScaleStart: _scaleEnabled ? _handleScaleStart : null,
              onScaleUpdate: _scaleEnabled ? _handleScaleUpdate : null,
              child: CustomPaint(
                  painter: _GesturePainter(
                      zoom: _zoom,
                      offset: _offset,
                      scaleEnabled: _scaleEnabled,
                  ),
                child: CustomPaint(
                    painter: GesturePainter2(
                      zoom: _zoom,
                      offset: _offset,
                      scaleEnabled: _scaleEnabled,
                    ),
              )
            ),
          )
        ]
    );
  }
}

有人可以帮我解决吗?

0 个答案:

没有答案