nateshmbhat / touchable

The only flutter library to add gestures and animations to custom shapes you draw on your canvas.
https://pub.dev/packages/touchable
Mozilla Public License 2.0
233 stars 79 forks source link

Touch event fire multi times unexpected #54

Open taosimple opened 1 year ago

taosimple commented 1 year ago
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        Expanded(
          child: CustomPaint(
            foregroundPainter: SelectionPainter(notifier: notifierForeground),
            child: RepaintBoundary(
              child: CanvasTouchDetector(
                //key: UniqueKey(),
                gesturesToOverride: const [
                  GestureType.onTapDown,
                ],
                builder: (BuildContext context) {
                  return CustomPaint(
                    isComplex: true,
                    willChange: false,
                    painter: ChartPainter<D, Rx, Ry>(
                      onItemSelected: (List<Rect> selectionRects, item, index, xAxisIndex, layer, tapEvent) {
                        notifierForeground.value = selectionRects;
                        _showTooltip(selectionRects);
                      },
                    ),
                  );
                },
              ),
            ),
          ),
        ),
      ],
    );
  }

After state.build called multi times, onTapDown event will also fire multi times with one click. It seems pre touch rects not cleared ?

Workaround: add UniqueKey to CanvasTouchDetector

Sri-Kumaran-DR commented 7 months ago

@taosimple workaround didn't help in my case. I have it wrapped in an InteractiveViewer. It still fires it multiple times