touchable
touchable copied to clipboard
touchable need to accpect canvas transform data.
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;
}
Sorry, I just saw the roadmap after posting this issue, hope can support canvas transform sooner.
Issue also reported here: #53
@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.