avoid_unnecessary_gesture_detector
v0.4.0 Warning Fix Widget Best Practices
This rule flags GestureDetector widgets that have no event handler callbacks (no onTap, onLongPress, onDoubleTap, etc.). A GestureDetector without any handlers does nothing useful but still participates in hit testing, which can interfere with gesture recognition for widgets below it.
Why use this rule
Section titled “Why use this rule”A handler-less GestureDetector is dead code that adds clutter to the widget tree. It may also unintentionally swallow touch events from child widgets, especially when behavior is set to HitTestBehavior.opaque. Removing it or adding the intended handler makes the code correct and easier to understand.
See also: GestureDetector | InkWell
// GestureDetector without any on* callbackGestureDetector(child: Text('hello'))
// Non-handler arguments like behavior don't countGestureDetector(behavior: HitTestBehavior.opaque, child: Text('world'))GestureDetector(onTap: () => print('tapped'), child: Text('hello'))
GestureDetector( onLongPress: () => print('long pressed'), onDoubleTap: () => print('double tapped'), child: Text('world'),)Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: avoid_unnecessary_gesture_detector: false