Flutter: Gesture detector,InkWell

 

 Image for post  

1 Wrap your widget using GestureDetector:

@override
Widget build(BuildContext context) {
return GestureDetector(
dragStartBehavior: DragStartBehavior.start, // default
child: Container(....
 

2 Adding callback functions

For getting information about where the gesture started we will need to add an implementation of two functions: onHorizontalDragStart and onVerticalDragStart .

return GestureDetector(
onHorizontalDragStart: _onHorizontalDragStartHandler,
onVerticalDragStart: _onVerticalDragStartHandler,

behavior: HitTestBehavior.translucent,
child: Container(...

 

3. Tap

onTap: () {
... do something
},

4.Double-tap

onDoubleTap: () {
print("DOUBLE TAB");
},

 

5. Long press

onLongPress: () {
print("Long press");
},
 

6. Button click

And what if we have a RaisedButton with onPressed handler in our Container that is wrapped with GestureDetector?

RaisedButton(
onPressed: () {
print('Button pressed');
},
child: Text("CLICK ME"),
),
 

7. Pinch/Scale

For preventing errors you cannot have simultaneously vertical , horizontal and scale handlers in one GestureDetector.

onVerticalDragStart: (DragStartDetails details) {},
onVerticalDragUpdate: (DragUpdateDetails details) {},
onVerticalDragEnd: (DragEndDetails details) {},
onScaleStart: (ScaleStartDetails details) {},
onScaleUpdate: (ScaleUpdateDetails details) {},
onScaleEnd: (ScaleEndDetails details) {},

Comments

Popular posts from this blog

Flutter : Introduction

How to release your Flutter app

Firebase Cloud Messaging