Browse Source

spinner spinning on empty query fix

ashilkn 2 years ago
parent
commit
d41d4ad02e
2 changed files with 6 additions and 4 deletions
  1. 2 2
      lib/ui/viewer/search/search_widget.dart
  2. 4 2
      lib/utils/search_debouncer.dart

+ 2 - 2
lib/ui/viewer/search/search_widget.dart

@@ -144,14 +144,14 @@ class _SearchWidgetState extends State<SearchWidget> {
 
   @override
   void dispose() {
-    _debouncer.cancel();
+    _debouncer.cancelDebounce();
     super.dispose();
   }
 
   Future<List<SearchResult>> getSearchResultsForQuery(String query) async {
     final List<SearchResult> allResults = [];
     if (query.isEmpty) {
-      _debouncer.cancel();
+      _debouncer.cancelDebounce();
       return (allResults);
     }
 

+ 4 - 2
lib/utils/search_debouncer.dart

@@ -6,7 +6,7 @@ class Debouncer {
   final Duration _duration;
   final ValueNotifier<bool> _debounceActiveNotifier = ValueNotifier(false);
   Timer _debounceTimer;
-  
+
   Debouncer(this._duration);
 
   void run(Future<void> Function() fn) {
@@ -20,9 +20,11 @@ class Debouncer {
     _debounceActiveNotifier.value = true;
   }
 
-  void cancel() {
+  void cancelDebounce() {
+    print('cancel');
     if (_debounceTimer != null) {
       _debounceTimer.cancel();
+      _debounceActiveNotifier.value = false;
     }
   }