proposal: avoid_unnecessary_gesture_detectors
#4872
Labels
lint-proposal
set-flutter
Affects a rule in the recommended Flutter rule set
status-pending
type-enhancement
A request for a change that isn't a bug
avoid_unnecessary_gesture_detectors
I propose the following new lint rule, to avoid a pitfall with GestureDetectors.
Description
Do not create GestureDetectors without gesture handlers.
Details
Given a
GestureDetector
widget frompackage:flutter/widgets.dart
, it is redundant if it has no handlers set at all.Kind
It does guard against errors somewhat. I.e. placing redundant widgets, or when a GestureDetector that used to do something, now does nothing because its last handler was removed.
Bad Examples
or even special casing the empty function
(){}
, if possible without side effects. Using a(){}
is sometimes used as a placeholder so I'm not sure about that.Good Examples
Discussion
It somewhat overlaps with https://dart.dev/tools/linter-rules/avoid_unnecessary_containers but they target different widgets.
I originally filed a proposal here: flutter/flutter#99686
A real-world use case would have been some code I wrote a while back.
It had a
GestureDetector
wrapping around a very largechild
definition, which made me miss the fact that it had no handlers.I was under the assumption of "This widget has a GestureDetector, why isn't it doing anything?", and it took me a bit to figure it out (in part due to the large widget tree obscuring my view somewhat).
Discussion checklist
The text was updated successfully, but these errors were encountered: