Closed miri-red closed 2 years ago
If I remember correctly, there is no method to stop the pattern on iOS. I'll check once again.
hi benjamindean what do you think about AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate) ?
@baobao2304 That might work, but not for the pattern unfortunately.
@benjamindean I think this is not bad , you can try that , its worked with me .
bool isCheckStop = false;
int counter = 0;
Timer? timer;
void startVibrationIOS(){
timer = Timer.periodic(Duration(seconds: 1), (timer) {
if (counter < 20) {
if(isCheckStop) {
isCheckStop = false;
counter = 0 ;
timer.cancel();
}
else{
if(counter % 2 == 0) {
Vibration.vibrate(duration: 500);
}
else {
Vibration.vibrate(duration: 1000);
}
}
} else{
timer.cancel();
counter = 0 ;
}
});
}
void stopVibrationIOS(){
isCheckStop = true;
}
void startVibrate(){
if(Platform.isAndroid){
Vibration.vibrate(
pattern: List.generate(20, (index) => index % 2 == 0 ? 500 : 1000));
}else{
startVibrationIOS();
}
}
void stopVibrate() {
if(Platform.isAndroid){
Vibration.cancel();
}else{
stopVibrationIOS();
}
}
I have vibration turned on with a pattern but in some cases I want the vibration to stop earlier, so I use Vibration.cancel(). On android it works great but on iOS it seems to continue to vibrate until the pattern is done.