touchable icon indicating copy to clipboard operation
touchable copied to clipboard

touchable need to accpect canvas transform data.

Open gzlock opened this issue 1 year ago • 3 comments

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 avatar Jul 10 '23 09:07 gzlock

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

gzlock avatar Jul 10 '23 09:07 gzlock

Issue also reported here: #53

morgano86 avatar Jul 12 '23 15:07 morgano86

@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.

sonnyvesali avatar Jul 25 '23 21:07 sonnyvesali