Skip to content

gesture_detector_without_handler

Reports a GestureDetector given no handler. Add the handler you meant, or use its child alone.

Tier
advisory
Scope
Flutter
Lowest preset
recommended
Fix
puts the child of the detector in its place

A Flutter GestureDetector given no handler: no argument whose name starts with on, such as onTap, with a value other than the literal null. The violation is on the constructor’s name.

The fix replaces the detector with its child. It is not offered for a detector without one.

The rule is silent in a package that does not use Flutter.

The detector detects gestures for nobody and only adds widgets to the tree. It is usually a handler that was forgotten or removed.

Violating
GestureDetector(child: Text(title))
Corrected
Text(title)

Set under the assay: key of the project’s root analysis_options.yaml.

Rule parameter Default Effect
enabled true false switches the rule off for the whole project.
exclude [] Path globs where the rule is silent.

Write why on the line directly above the suppression:

// Why this place is fine.
// ignore: gesture_detector_without_handler

// ignore_for_file: assay/gesture_detector_without_handler silences it in a whole file, and // ignore: assay/gesture_detector_without_handler with the prefix works too. See Suppressions.