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 80 forks source link

touchable need to accpect canvas transform data. #57

Open gzlock opened 1 year ago

gzlock commented 1 year ago

The canvas transform(translate, scale, clilpRect) has no effect on TouchyCanvas demo

import 'package:flutter/material.dart';
import 'package:touchable/touchable.dart';

void main() {
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CanvasTouchDetector(
        builder: (context) => CustomPaint(painter: MyPainter(context)));
  }
}

class MyPainter extends CustomPainter {
  final BuildContext context;

  MyPainter(this.context);

  @override
  void paint(Canvas canvas, Size size) {
    canvas.scale(10);
    canvas.translate(50, 50);
    /// set the transform before create the TouchyCanvas
    var myCanvas = TouchyCanvas(context, canvas);
    myCanvas.drawCircle(Offset(10, 10), 60, Paint()..color = Colors.orange,
        onTapDown: (tapdetail) {
      print("orange Circle touched");
    }, onPanDown: (tapdetail) {
      print("orange circle swiped");
    });
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}
gzlock commented 1 year ago

Sorry, I just saw the roadmap after posting this issue, hope can support canvas transform sooner.

morgano86 commented 1 year ago

Issue also reported here: #53

sonnyvesali commented 1 year ago

@gzlock If your painting isn't super complex you can wrap your canvas in a GestureDetector widget and make your paintings pseudo- interact-able that way, it's kind of a workaround and doesn't work for more complex use cases but figured I'd mention it for anyone else who's running into this bottleneck.