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

Click on the failure #32

Open jahnli opened 3 years ago

jahnli commented 3 years ago

import 'dart:math'; import 'dart:ui';

import 'package:flutter/material.dart';

import 'package:touchable/touchable.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key);

@override _MyAppState createState() => _MyAppState(); }

class _MyAppState extends State { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Container( color: Colors.white, //wrap CustomPaint with CanvasTouchDetector child: CanvasTouchDetector( builder: (context) => CustomPaint( painter: MyPaintere(context), ), ), ), )); } }

class MyPaintere extends CustomPainter { final BuildContext context; MyPaintere(this.context); // context from CanvasTouchDetector @override void paint(Canvas canvas, Size size) { //Create and use TouchyCanvas to draw TouchyCanvas touchyCanvas = TouchyCanvas(context, canvas);

var blueCircle = Offset(size.width / 2 + 200, size.height / 2 + 100);
var greenCircle = Offset(size.width / 2 + 200, size.height / 2 + 300);

touchyCanvas.drawCircle(blueCircle, 60, Paint()..color = Colors.blue, onTapDown: (_) {
  print('You clicked BLUE circle');
});

touchyCanvas.drawCircle(greenCircle, 30, Paint()..color = Colors.green, onLongPressStart: (_) {
  print('long pressed on GREEN circle');
});

}

@override bool shouldRepaint(CustomPainter oldDelegate) { return false; } }

jahnli commented 3 years ago

When I run demo, it doesn't respond onTapDown onLongPressStart