• Stars
    star
    218
  • Rank 176,291 (Top 4 %)
  • Language
    Dart
  • License
    Mozilla Public Li...
  • Created about 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flutter library to add gestures and animations to each Shape you draw on your canvas in your CustomPainter

Flutter library to bring your CustomPainter 🎨 to Life ⚡️

touchable library gives you the ability to add various gestures and animations to each Shape you draw on your canvas in the CustomPainter


           

Index :

Why Use Touchable ?

  • The CustomPainter lets you only draw shapes on the canvas. But most would want to let user interact with the drawings.

  • Add all kinds of gesture callbacks to each drawing to give interaction capability to the shapes you draw on the canvas.

  • Animating individual shapes has never been this easy.

  • Auto Handles the painting style (filled ▮ , stroke ▯) and detects touch accordingly.

  • Handles Painting stroke width. So if your shapes are painted thick , we still got it covered ✓

  • Supports clipping and different clipping modes for the drawings.

  • Supports HitTestBehavior for each shape.

  • Simple and Easy API. Just wrap your CustomPaint with CanvasTouchDetector and use the TouchyCanvas in your painter.

With touchable , you get what the normal canvas always missed : touchability 😉

Installation

Add the touchable package as dependency in your pubspec.yaml

dependencies:
  touchable:

Usage

  • 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
    });
  }
}

Read the article on Medium : Bring Your CustomPainter to Life using Touchable



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 , order , clippings 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

  • Basic Shape Detection
    • Line
    • Rectangle (Rect)
    • Circle
    • Oval or Ellipse
    • Arc
      • segment
      • sector
    • Rounded Rectangle (RRect)
    • Custom Path [only supports opaque hittest]
    • Points (PointMode.points , PointMode.lines , PointMode.polygon)
    • Vertices
      • Traingle
      • Traingle Strip
      • Traingle Fan
  • Support for proper edge detection based on the Paint object properties :
    • Paint style
    • Stroke Width
    • Stroke Cap
      • StrokeCap to draw Points
      • StrokeCap.round for lines with huge width.
  • Support Clipping and clipping modes
    • ClipRect
      • intersect mode [Touch detection enabled only inside the clipped region]
      • difference mode [Touch detection enabled only outside the clipped region]
    • ClipRRect
    • ClipPath
  • 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

Links

More Repositories

1

pyttsx3

Offline Text To Speech synthesis for python
Python
1,765
star
2

webbot

Web automation library for simple and easy end to end testing and web browser automation that offers super charged features while keeping it simple to use and master
Python
234
star
3

electron-react-ts-starter

A solid :) boiler plate starter pack when starting an electron project which uses create-react-app with typescript.
TypeScript
111
star
4

card-scanner-flutter

A flutter package for Fast, Accurate and Secure Credit card & Debit card scanning
Swift
94
star
5

windows-terminal-tweaker

Tweak your windows terminal to heart's content with this app using its beautiful interface to configure everything about the terminal.
TypeScript
90
star
6

pyYify

This is a python library used to get the Top seeded torrents at any given time and get the entire movie details and ratings . Its also useful to search for any movie using different parameters and obtain their magnet link or torrent file of any preferred quality.
Python
56
star
7

svelte-ace

Ace Editor component for Svelte with TypeScript support 🥳🥳
Svelte
43
star
8

rm-trash

A "rm-trash" is meant to be used in place of rm system command in linux . This script will safely delete your files and put them in the trash for later retrieval.
Shell
40
star
9

cardano-nft-minter

A script that handles minting cardano native tokens in a simple and interactive way.
Shell
29
star
10

tap-rpc

The tool you need for your GRPC clients and backends
TypeScript
24
star
11

torrento

A Dart package that wraps various Web Apis for controlling and managing torrent clients.
Dart
15
star
12

snakes

A LAN Multiplayer Snake game in C++ . This is a snake game which is a console based game written in C++ to which any number of players in LAN can join and play with their corresponding snakes with smooth synchronization.
C++
14
star
13

svelte-electron-ts-starter

This is a boiler plate starter pack when starting an electron project which uses svelte with typescript ⚡
TypeScript
10
star
14

tap-rest

TypeScript
9
star
15

coder-chat

A webapp built with react and express that is useful during coding sessions and other use cases that involve chatting and coding
TypeScript
6
star
16

flutter-snake-tutorial

Snake game made in flutter ! Hissss !
Dart
4
star
17

use-game-of-life

Demo of useGameOfLife
TypeScript
2
star
18

cns-lab-sit

Cryptography And Network Security Lab Programs
C++
2
star
19

flutter-multi-module-app

Sample multi module flutter app
Ruby
2
star
20

grpc-with-electron-sample-project

This project demonstrates an issue with grpc when run inside electron.
JavaScript
2
star
21

nateshmbhat

1
star
22

Regression

This repo contains many training models of Linear and Logistic regression implemented at lower level without using libraries like tensorflow.
Jupyter Notebook
1
star
23

traffic-manager

Intel Higher Education challenge project which applies image processing for vehicles and uses the processed data to handle the traffic.
Python
1
star
24

Subtitle-grabber

Gets the subtitles for the video file or multiple videos in a specified directory.
Python
1
star
25

nateshmbhat.github.io

JavaScript
1
star
26

stream-it-desktop-app

The power to stream tons of music from your PCs onto your phones effortlessly.
Java
1
star
27

simple-countdown-timer

A countdown timer which is built to be used for a hackathon that we hosted.
JavaScript
1
star
28

stream-it-android-app

Android app for streaming music on LAN.
Java
1
star
29

timetable

Time table allotment Project which aims to automate the allotment of classes to available faculties and forming the time table.
Jupyter Notebook
1
star
30

nuclei-flutter-poc-qr-code-scanner

Dart
1
star
31

dart-tutorial

Dart tutorial notes
1
star
32

algorithms

An Algorithm must be seen to be believed
C++
1
star
33

torrential-lib-mobile-app

A demo flutter app which shows the usage of the torrential-lib library.
Dart
1
star
34

nuclei-assignment-2020-mobile

Freshers Assignment 2020 - Mobile Developer
Java
1
star
35

react-native-screen-resizer

Test your react native app across various device screen sizes and supercharge your application's responsiveness.
TypeScript
1
star
36

safe-rm-python

A safe "rm" script which is meant to be used in place of rm system command in linux . This script will safely delete your files and put them in the trash. This solves accidental removals.
Python
1
star