浏览代码

handled cases where toggle's onChanged returns an error

ashilkn 2 年之前
父节点
当前提交
64591cf02c
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3 1
      lib/ui/components/toggle_switch_widget.dart

+ 3 - 1
lib/ui/components/toggle_switch_widget.dart

@@ -76,7 +76,9 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
                   );
                   );
                 });
                 });
                 final Stopwatch stopwatch = Stopwatch()..start();
                 final Stopwatch stopwatch = Stopwatch()..start();
-                await widget.onChanged.call();
+                await widget.onChanged.call().onError(
+                      (error, stackTrace) => _debouncer.cancelDebounce(),
+                    );
                 //for toggle feedback on short unsuccessful onChanged
                 //for toggle feedback on short unsuccessful onChanged
                 await _feedbackOnUnsuccessfulToggle(stopwatch);
                 await _feedbackOnUnsuccessfulToggle(stopwatch);
                 //debouncer gets canceled if onChanged takes less than debounce time
                 //debouncer gets canceled if onChanged takes less than debounce time