Handle taps on a non-button Container: GestureDetector vs InkWell
This tests gesture propagation and Material feedback. Use GestureDetector for raw taps, drags, or scales; InkWell for Material ripples, which needs a Material ancestor. Red flag: InkWell without Material or ignoring GestureDetector drag support.
WHAT THIS TESTS: This question checks if you know how the Flutter gesture system and Material ink splash system interact in the widget tree. It is not just about syntax; the interviewer wants to see that you understand when to provide visual feedback, how gestures propagate, and why some widgets need specific ancestors to render correctly.
A GOOD ANSWER COVERS: A good answer hits four things in order. First, explain that a Container or other non-button widget has no built-in gesture handling, so you must wrap it in a gesture widget. Second, describe GestureDetector as the low-level, highly configurable option that exposes callbacks for taps, double taps, long presses, drags, scales, and pans without imposing any visual effects. Third, describe InkWell as a Material-specific widget that adds a ripple splash on tap and requires a Material ancestor in the tree because the splash is painted by the Material widget itself. Fourth, note the practical rule of thumb: use GestureDetector when you need custom visuals or non-tap gestures, and use InkWell when you want standard Material touch feedback on a custom widget.
COMMON WRONG ANSWERS: The biggest red flag is saying InkWell will show ripples on any background without a Material widget; in practice, the splash paints onto the Material and will look wrong or invisible if that ancestor is missing. Another red flag is treating InkWell as a universal replacement for GestureDetector and missing that InkWell does not expose the full suite of gesture callbacks like onPanUpdate or onScaleStart. A third pitfall is nesting multiple gesture detectors without explaining how the gesture arena resolves conflicts, though that is usually a follow-up topic.
LIKELY FOLLOW-UPS: An interviewer might ask how you would add a ripple to a widget that has a non-rectangular shape or an image background, which leads to using Ink with a custom border radius or clipping. They might also ask how gesture disambiguation works when a parent and child both have gesture detectors, or why a GestureDetector on a transparent area might not receive events if the hit test behavior is not set correctly.
ONE CONCRETE EXAMPLE: Imagine a card in a social media feed that should show a ripple when tapped to open a detail screen. Wrapping the card in an InkWell inside a Material widget gives the standard splash. If the same card needs to be draggable to dismiss, you would switch to a GestureDetector with a Dismissible or a drag callback, because InkWell does not handle horizontal drags by default and GestureDetector gives you the control to define the drag threshold and animation yourself.
Read the original → docs.flutter.dev
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.