Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

library to add various gesture callbacks

library to add various gesture callbacks

flutter library to add various gesture callbacks to each shape you draw on your canvas in your custompainter.

library to add various gesture callbacks

touchable

why use touchable ?

library to add various gesture callbacks

  • the custompainter lets you only draw shapes on the canvas. but most would want to let user interact with the drawings.
  • with touchable , you get what the normal canvas always missed : touchability ��
  • with this , its possible to add all kinds of gesture callbacks to each drawing and thus interaction capability to each shape you draw on the canvas.
  • animating individual shapes becomes so much easier than ever before.
  • handles the painting style (filled ▮ , stroke ▯) and detects touch accordingly.
  • takes the painting stroke width also into account. so if your shapes are painted thick , we still got it covered ✓
  • supports clipping and different clipping modes. so, you can have any kind of complex clipping and drawing combinations while getting full interactive capability.
  • supports hittestbehavior for each shape.
  • simple and easy api. just wrap your custompaint with canvastouchdetector and use the touchycanvas in your painter.

installation

library to add various gesture callbacks

add the touchable package as dependency in your pubspec.yaml

dependencies:
  touchable:

usage :

library to add various gesture callbacks

  • just wrap your custompaint widget with canvastouchdetector. it takes a builder function as argument that expects your custompaint widget as shown below.
canvastouchdetector(
    builder: (context) => 
        custompaint(
            painter: mypainter(context)
        )
)
  • inside your custompainter class’s paint method , create and use the touchycanvas object (using the context obtained from the canvastouchdetector and canvas) to draw any shape with different gesture callbacks.
var mycanvas = touchycanvas(context,canvas);
mycanvas.drawrect( rect , paint() , ontapdown: (tapdetail){
    //do stuff here. probably change your state and animate
});

mypainter example :

class mypainter extends custompainter {

  final buildcontext context ;
  mypainter(this.context); // context from canvastouchdetector

  @override
  void paint(canvas canvas, size size) {
    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");
        } 
    );

    mycanvas.drawline(
        offset(0, 0),
        offset(size.width - 100, size.height - 100),
        paint()
          ..color = colors.black
          ..strokewidth = 50, 
        onpanupdate: (detail) {
            print('black line swiped'); //do cooler things here. probably change app state or animate
    });
  }
}

how touchable works :

when you draw shapes on the canvas (touchycanvas) , it keeps track of the dimensions of each shape you draw and their painting style , stroke etc.

when user performs any gesture on the screen , based on the location of the gesture , the appropriate shape is selected from the lot taking clipping regions , paint , hittest behaviour etc into account in an optimized way. callbacks of the corresponding shapes (one or more depending on the hittest behavior) are executed.

road map

  • [x] basic shape detection
    • [x] line
    • [x] rectangle (rect)
    • [x] circle
    • [x] oval or ellipse
    • [x] arc
      • [x] segment
      • [x] sector
    • [x] rounded rectangle (rrect)
    • [x] custom path [only supports opaque hittest]
    • [x] points (pointmode.points , pointmode.lines , pointmode.polygon)
    • [ ] vertices
      • [ ] traingle
      • [ ] traingle strip
      • [ ] traingle fan
  • [x] support for proper edge detection based on the paint object properties :
    • [x] paint style
    • [x] stroke width
    • [ ] stroke cap
      • [x] strokecap to draw points
      • [ ] strokecap.round for lines with large width
  • [x] support clipping and clipping modes
    • [x] cliprect
      • [x] intersect mode [touch detection enabled only inside the clipped region]
      • [x] difference mode [touch detection enabled only outside the clipped region]
    • [x] cliprrect
    • [x] clippath
  • [x] support for hittestbehavior
  • [ ] make the touch detection handling to run in a seperate isolate.
  • [ ] support for translation , rotation , scaling and skewing transformations that needs some vector math

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.