Home > Back-end >  How to disable haptic feedback in showTimePicker()?
How to disable haptic feedback in showTimePicker()?

Time:12-15

In Flutter, if you show a time picker by calling showTimePicker(), it will heavily vibrate when picking the time (in dial mode).

Is there a way to disable the time picker dialogs haptic feedback?

CodePudding user response:

Looking at the source code, you can see that everything related to vibration is private API

  void _vibrate() {
    switch (Theme.of(context).platform) {
      case TargetPlatform.android:
      case TargetPlatform.fuchsia:
      case TargetPlatform.linux:
      case TargetPlatform.windows:
        _vibrateTimer?.cancel();
        _vibrateTimer = Timer(_kVibrateCommitDelay, () {
          HapticFeedback.vibrate();
          _vibrateTimer = null;
        });
        break;
      case TargetPlatform.iOS:
      case TargetPlatform.macOS:
        break;
    }
  }
  void _handleTimeChanged(TimeOfDay value) {
    _vibrate();
    setState(() {
      _selectedTime.value = value;
    });
  }

So unfortunately, the only clean way is to create your own TimePickerDialog and change that behavior.

  • Related