Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: InkWell vs GestureDetector: what is the difference?

I'm completely new to Flutter and found out about InkWell and GestureDetector. It seemed to me that they are almost the same. The official documentation doesn't provide any in-depth comparison between them.

  1. What are the differences between InkWell and GestureDetector?

  2. When to use which?

like image 958
sphoenix Avatar asked Jun 23 '19 15:06

sphoenix


People also ask

What is the difference between InkWell and InkResponse widget in Flutter?

InkResponse is an area of Material widget that responds when being touched by showing splash. Unlike InkWell , the shape of InkResponse can be configured. You can also configure whether it should clip the splash.

What is InkWell in Flutter?

Flutter's InkWell class The InkWell class is a rectangular area of a Material widget that responds to touch events by displaying a clipped splash. The Material widget is responsible for the ink effects that are displayed when a touch event occurs. The Material refers to the area where the ink reactions are painted.

What is GestureDetector Flutter?

Gesture Detector in Flutter is used to detect the user's gestures on the application. It is a non-visual widget. Inside the gesture detector, another widget is placed and the gesture detector will capture all these events (gestures) and execute the tasks accordingly.

What is the difference between InkWell and GestureDetector in Flutter?

They both look the same and almost do the same thing, so what is difference between flutter InkWell vs GestureDetector? Generally speaking, GestureDetector provides more gesture control to detect almost every user interaction including dragging, swiping, pinching, etc.


1 Answers

Differences:

  1. They both provide many common features like onTap, onLongPress etc. The main difference is GestureDetector provides more controls like dragging etc. on the other hand it doesn't include ripple effect tap, which InkWell does.

  2. You can use either of them according to your needs, you want ripple effects go with InkWell, need more controls go with GestureDetector or even combine both of them.


Ripple effect (using InkWell):

InkWell(   onTap: () {},   child: Ink(     width: 200,     height: 200,     color: Colors.blue,   ), ) 

enter image description here

like image 94
CopsOnRoad Avatar answered Oct 10 '22 19:10

CopsOnRoad