A GestureDetector inside a Stack never fires onTap
GestureDetector onTap is never calledShort answer
A tap does nothing when the detector has nothing to hit, when another widget sits on top and takes the hit, or when a nested detector wins the gesture. Turn on debugPaintPointersEnabled to see the hit areas, then set behavior to opaque, wrap the overlay in IgnorePointer, or remove the competing detector.
Fix it fast
1Find out which cause you have
Make Flutter draw the area each pointer target covers. Add this line before runApp, hot restart, and tap. If your detector has no box on screen, it has no hit area.
import 'package:flutter/rendering.dart'; void main() { debugPaintPointersEnabled = true; runApp(const MyApp()); }2Match what you see, then jump to its fix
- 1
No hit box is drawn over the detector, or only over the part that has visible contentThe detector's child is empty or transparentFix - 2
The tap reaches nothing, or reaches the wrong layer, and the pointer debug box sits on the top widgetA widget stacked on top takes the hitFix - 3
The inner onTap runs and the outer onTap never doesA nested detector wins the gestureFix
- 1
What does the error look like?
GestureDetector onTap is never calledContainer inside Stack does not respond to tapsTap goes to the widget underneath instead of the top one
Cause 1 of 3
The detector's child is empty or transparent
1Check
By default a GestureDetector only takes hits where its child takes hits. A Container with no color and no child, or a SizedBox, gives it nothing to hit. A GestureDetector with no child at all expands to fill its parent.
GestureDetector(
onTap: () => debugPrint('tap'),
child: Container(width: 120, height: 120), // no color: nothing to hit
)2Fix
Set behavior to HitTestBehavior.opaque, so the detector claims its whole box. Use translucent if widgets behind it must also get the touch.
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => debugPrint('tap'),
child: Container(width: 120, height: 120),
)3Verify
Tap the empty area and look for the print in the debug console.
flutter runConfirmed by api.flutter.dev
Cause 2 of 3
A widget stacked on top takes the hit
1Check
Children of a Stack paint in order, and the first child is at the bottom. Whatever comes later covers the earlier ones and is hit first. A full-size overlay, gradient or blur layer often sits on top of the button without being obvious.
Stack(
children: [
GestureDetector(onTap: () {}, child: const Text('Buy')), // bottom
Container(color: Colors.black26), // covers it
],
)2Fix
Wrap the decorative overlay in IgnorePointer, so it still paints but is skipped by hit testing. Or move the detector to a later child.
Stack(
children: [
const Text('Buy'),
IgnorePointer(child: Container(color: Colors.black26)),
],
)3Verify
Tap through the overlay area. The widget below now answers.
flutter runConfirmed by api.flutter.dev
Cause 3 of 3
A nested detector wins the gesture
1Check
When detectors overlap, each enters the gesture arena and only one wins. The child enters first and wins, so a parent's onTap does not run for taps on the child. Setting behavior on the parent does not change this contest.
grep -rn "GestureDetector\|InkWell" lib/ | head -302Fix
Keep one tap handler for that area: remove the inner detector, or move the logic into the inner one. To inspect the contest, print the arena diagnostics.
import 'package:flutter/gestures.dart';
void main() {
debugPrintGestureArenaDiagnostics = true;
runApp(const MyApp());
}3Verify
Tap once and read the arena lines in the console to see which recognizer won.
flutter runConfirmed by api.flutter.dev
How do I stop it coming back?
- Give any tappable area a visible size or set behavior explicitly instead of relying on the default.
- Put purely decorative layers inside IgnorePointer when you add them to a Stack.
- Keep debugPaintPointersEnabled in a debug-only toggle so hit areas are one switch away.
- Use one tap handler per area.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix