颤振中堆叠形状的手势检测

时间:2020-05-14 21:34:02

标签: flutter gesturedetector

我已经花了好几个小时来努力为这个小部件获取GestureDetection方法。

我有一个按钮,当按下该按钮时,饼图的比例会从零变为1。用户按住手指,然后放开它,饼图会缩小到零比例。这可行,但是...

当用户按下按钮时,我希望他们能够将手指拖动到现在可见的饼图上,并且让每个段在用户将其拖动时做出响应。

这是基本的小部件树:

 @override
  Widget build(BuildContext context) {
    //print('your container list is ${containerList}');
    return Container(
      width: 80,
      height: 80,
      decoration: BoxDecoration(
        color: Colors.amber,
      ),
      child: Stack(
        alignment: Alignment.center,
        children: <Widget>[
          PieChartContainer(),
          GestureDetector(
            onPanDown: (DragDownDetails details) {MakePieChartBig()},
            onTapUp: (TapUpDetails details) {MakePieChartSmall()},
            child: Container(width: 70, height: 70,
              child: CustomPaint(
                painter: CircleButton(radius: 35),
              ),
            ),
          ),
        ],
      ),
    );
  }

因此,您可以按住CircleButton和PieChartContainer缩放比例从0到1。 PieChart容器为:

 Widget PieChartContainer() {
    return OverflowBox(
      minWidth: 0.0,
      minHeight: 0.0,
      maxWidth: double.infinity,
      maxHeight: double.infinity,
      // this Tweet scales the whole chart using MakePieChartBig(), this works ok.
      child: TweenAnimationBuilder(
        tween: _scaleTween,
        curve: Curves.easeOut,
        duration: Duration(milliseconds: 100),
        builder: (context, scale, child) {
          return Transform.scale(scale: scale, child: child);
        },
        child: Stack(
          alignment: Alignment.center,
          /// when the chart is big and the user drags their finger around
          /// each one of these chart segments should respond when the
          /// users finger interacts with it
          children: <Widget>[
            CustomPaint(painter: ChartSegment(60, Colors.blue, 0.0, 3.14 / 2)),
            CustomPaint(painter: ChartSegment(60, Colors.red, 3.14 / 2, 3.14 / 2)),
            CustomPaint(painter: ChartSegment(60, Colors.amber, 3.14, 3.14 / 2)),
            CustomPaint(painter: ChartSegment(60, Colors.green, 3.14 * 1.5, 3.14 / 2)),
          ],
        ),
      ),
    );
  }

所以我想我可以将每个custompaint的ChartSegment包装在GestureDetector中并获取onDragUpdate ...但这无济于事。我在这里的其他线程指定的整个堆栈上尝试了一个侦听器,然后尝试了一个名为Touchable的程序包,但这不适用于堆栈中的对象。

在AS3中,我使用eventlisteners和event.CurrentTarget可以很容易地完成此工作。Flutter是否具有类似的功能?还是我需要其他方法?

0 个答案:

没有答案