소스 검색

show toggle feedback on short unsuccessful onchanged

ashilkn 2 년 전
부모
커밋
1b245a5021
1개의 변경된 파일12개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      lib/ui/components/toggle_switch_widget.dart

+ 12 - 0
lib/ui/components/toggle_switch_widget.dart

@@ -71,7 +71,10 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
                     ),
                   );
                 });
+                final Stopwatch stopwatch = Stopwatch()..start();
                 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.cancelDebounce();
                 setState(() {
@@ -115,4 +118,13 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
       return const SizedBox.shrink();
     }
   }
+
+  Future<void> _feedbackOnUnsuccessfulToggle(Stopwatch stopwatch) async {
+    final timeElapsed = stopwatch.elapsedMilliseconds;
+    if (timeElapsed < 200) {
+      await Future.delayed(
+        Duration(milliseconds: 200 - timeElapsed),
+      );
+    }
+  }
 }