Skip to main content

avoid-unnecessary-gesture-detector

added in: 1.15.0
Pro+
preset: recommended

Warns when a GestureDetector widget has no event handlers.

Gesture detectors with no handlers have no additional functionality and can be safely removed (or updated to have at least one handler).

Example

❌ Bad:

// LINT: This 'GestureDetector' has no event handlers. Try passing an event handler (e.g. 'onTap') or removing this widget.
GestureDetector(
child: Widget(),
);

✅ Good:

GestureDetector(
onTapDown: () {
...
},
child: Widget(),
);