From c2f30665ece89f6768d7aa30dbbc3503465c8ae9 Mon Sep 17 00:00:00 2001 From: krawieck Date: Thu, 24 Sep 2020 16:26:24 +0200 Subject: [PATCH] make disposal non-manual --- lib/hooks/debounce.dart | 5 ++--- lib/pages/add_instance.dart | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/hooks/debounce.dart b/lib/hooks/debounce.dart index 5a1fc4a..3c7c217 100644 --- a/lib/hooks/debounce.dart +++ b/lib/hooks/debounce.dart @@ -8,7 +8,6 @@ import 'ref.dart'; class Debounce { final bool loading; final void Function() callback; - final void Function() dispose; void call() => callback(); @@ -17,7 +16,6 @@ class Debounce { const Debounce({ @required this.loading, @required this.callback, - @required this.dispose, }); } @@ -35,6 +33,8 @@ Debounce useDebounce( loading.value = false; } + useEffect(() => () => timerHandle.current?.cancel(), []); + start() { timerHandle.current = Timer(delayDuration, () async { loading.value = true; @@ -49,6 +49,5 @@ Debounce useDebounce( cancel(); start(); }, - dispose: cancel, ); } diff --git a/lib/pages/add_instance.dart b/lib/pages/add_instance.dart index 734d1a3..b43b415 100644 --- a/lib/pages/add_instance.dart +++ b/lib/pages/add_instance.dart @@ -44,7 +44,6 @@ class AddInstancePage extends HookWidget { instanceController.addListener(debounce); return () { - debounce.dispose(); instanceController.removeListener(debounce); }; }, []);