prefer-haptic-feedback-on-interaction
Warns when a GestureDetector or InkWell onTap callback does not invoke HapticFeedback.
For blind, low-vision, or neurodivergent users, physical tactile response (vibration/haptics) provides essential non-visual confirmation that a touch gesture or button press was successfully registered by the OS.
Custom gesture targets (GestureDetector, InkWell) often omit HapticFeedback.vibrate() or HapticFeedback.selectionClick() calls in their callback blocks.
Example
❌ Bad:
class MyWidget extends StatelessWidget {
final void Function() callback;
const MyWidget(this.callback);
Widget build(BuildContext context) {
// LINT: Prefer calling one of HapticFeedback methods to provide non-visual confirmation that a tap was successfully registered by the OS.
GestureDetector(onTap: callback);
GestureDetector(
// LINT: Prefer calling one of HapticFeedback methods to provide non-visual confirmation that a tap was successfully registered by the OS.
onTap: () {
callback();
},
);
}
}
✅ Good:
class MyWidget extends StatelessWidget {
final void Function() callback;
const MyWidget(this.callback);
Widget build(BuildContext context) {
GestureDetector(
onTap: () {
HapticFeedback.vibrate();
callback();
},
);
GestureDetector(onTap: () => _withHaptic());
}
void _withHaptic() {
HapticFeedback.vibrate();
...
}
}