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.
What are the differences between InkWell
and GestureDetector
?
When to use which?
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.
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.
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.
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.
Differences:
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.
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, ), )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With