-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💾 Feat(Vibration): Add vibration handler and apply vibration to certa…
…in actions
- Loading branch information
1 parent
f375e41
commit 964ed37
Showing
7 changed files
with
102 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:sound_mode/sound_mode.dart'; | ||
import 'package:sound_mode/utils/ringer_mode_statuses.dart'; | ||
import 'package:vibration/vibration.dart'; | ||
|
||
/// [VibrationHandler] | ||
class VibrationHandler { | ||
/// [tryVibrate] | ||
static void tryVibrate({int milliseconds = 50}) { | ||
SoundMode.ringerModeStatus.then((ringer) { | ||
if (ringer == RingerModeStatus.silent) { | ||
return; | ||
} | ||
|
||
Vibration.hasVibrator().then((value) { | ||
Vibration.hasCustomVibrationsSupport().then( | ||
(value) { | ||
if (value ?? false) { | ||
Vibration.vibrate(duration: milliseconds); | ||
} else { | ||
Vibration.hasVibrator().then( | ||
(value) { | ||
if (value ?? false) Vibration.vibrate(); | ||
}, | ||
); | ||
} | ||
}, | ||
); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
/// [VibrationHandlerExtensions] | ||
extension VibrationHandlerExtensions on Function { | ||
/// [tryVibrate] | ||
Function tryVibrate({int milliseconds = 50}) { | ||
VibrationHandler.tryVibrate(milliseconds: milliseconds); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters