|
@@ -71,7 +71,10 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
|
|
),
|
|
),
|
|
);
|
|
);
|
|
});
|
|
});
|
|
|
|
+ final Stopwatch stopwatch = Stopwatch()..start();
|
|
await widget.onChanged.call();
|
|
await widget.onChanged.call();
|
|
|
|
+ //for toggle feedback on short unsuccessful onChanged
|
|
|
|
+ await _feedbackOnUnsuccessfulToggle(stopwatch);
|
|
//debouncer gets canceled if onChanged takes less than debounce time
|
|
//debouncer gets canceled if onChanged takes less than debounce time
|
|
_debouncer.cancelDebounce();
|
|
_debouncer.cancelDebounce();
|
|
setState(() {
|
|
setState(() {
|
|
@@ -115,4 +118,13 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
|
|
return const SizedBox.shrink();
|
|
return const SizedBox.shrink();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Future<void> _feedbackOnUnsuccessfulToggle(Stopwatch stopwatch) async {
|
|
|
|
+ final timeElapsed = stopwatch.elapsedMilliseconds;
|
|
|
|
+ if (timeElapsed < 200) {
|
|
|
|
+ await Future.delayed(
|
|
|
|
+ Duration(milliseconds: 200 - timeElapsed),
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|