Explorar o código

show loading icon when all search sections are getting loaded or reloaded

ashilkn hai 1 ano
pai
achega
9487c846a6
Modificáronse 2 ficheiros con 56 adicións e 38 borrados
  1. 4 1
      lib/states/all_sections_examples_state.dart
  2. 52 37
      lib/ui/search_tab.dart

+ 4 - 1
lib/states/all_sections_examples_state.dart

@@ -78,6 +78,7 @@ class _AllSectionsExamplesProviderState
   Widget build(BuildContext context) {
     return InheritedAllSectionsExamples(
       allSectionsExamplesFuture,
+      _debouncer.debounceActiveNotifier,
       child: widget.child,
     );
   }
@@ -85,8 +86,10 @@ class _AllSectionsExamplesProviderState
 
 class InheritedAllSectionsExamples extends InheritedWidget {
   final Future<List<List<SearchResult>>> allSectionsExamplesFuture;
+  final ValueNotifier<bool> isDebouncingNotifier;
   const InheritedAllSectionsExamples(
-    this.allSectionsExamplesFuture, {
+    this.allSectionsExamplesFuture,
+    this.isDebouncingNotifier, {
     super.key,
     required super.child,
   });

+ 52 - 37
lib/ui/search_tab.dart

@@ -74,44 +74,59 @@ class _AllSearchSectionsState extends State<AllSearchSections> {
     // remove face and content sectionType
     searchTypes.remove(SectionType.face);
     searchTypes.remove(SectionType.content);
-    return FutureBuilder(
-      future:
-          InheritedAllSectionsExamples.of(context).allSectionsExamplesFuture,
-      builder: (context, snapshot) {
-        if (snapshot.hasData) {
-          if (snapshot.data!.every((element) => element.isEmpty)) {
-            return const Padding(
-              padding: EdgeInsets.only(bottom: 72),
-              child: SearchTabEmptyState(),
-            );
-          }
-          return ListView.builder(
-            padding: const EdgeInsets.only(bottom: 180),
-            physics: const BouncingScrollPhysics(),
-            itemCount: searchTypes.length,
-            itemBuilder: (context, index) {
-              return SearchSection(
-                sectionType: searchTypes[index],
-                examples: snapshot.data!.elementAt(index),
-                limit: searchSectionLimit,
+    return Stack(
+      children: [
+        FutureBuilder(
+          future: InheritedAllSectionsExamples.of(context)
+              .allSectionsExamplesFuture,
+          builder: (context, snapshot) {
+            if (snapshot.hasData) {
+              if (snapshot.data!.every((element) => element.isEmpty)) {
+                return const Padding(
+                  padding: EdgeInsets.only(bottom: 72),
+                  child: SearchTabEmptyState(),
+                );
+              }
+              return ListView.builder(
+                padding: const EdgeInsets.only(bottom: 180),
+                physics: const BouncingScrollPhysics(),
+                itemCount: searchTypes.length,
+                itemBuilder: (context, index) {
+                  return SearchSection(
+                    sectionType: searchTypes[index],
+                    examples: snapshot.data!.elementAt(index),
+                    limit: searchSectionLimit,
+                  );
+                },
               );
-            },
-          );
-        } else if (snapshot.hasError) {
-          //todo: Show something went wrong here
-          //Errors are handled and this else if condition will be false always
-          //is the understanding.
-          return const Padding(
-            padding: EdgeInsets.only(bottom: 72),
-            child: EnteLoadingWidget(),
-          );
-        } else {
-          return const Padding(
-            padding: EdgeInsets.only(bottom: 72),
-            child: EnteLoadingWidget(),
-          );
-        }
-      },
+            } else if (snapshot.hasError) {
+              //todo: Show something went wrong here
+              //Errors are handled and this else if condition will be false always
+              //is the understanding.
+              return const Padding(
+                padding: EdgeInsets.only(bottom: 72),
+                child: EnteLoadingWidget(),
+              );
+            } else {
+              return const Padding(
+                padding: EdgeInsets.only(bottom: 72),
+                child: EnteLoadingWidget(),
+              );
+            }
+          },
+        ),
+        ValueListenableBuilder(
+          valueListenable:
+              InheritedAllSectionsExamples.of(context).isDebouncingNotifier,
+          builder: (context, value, _) {
+            return value
+                ? const EnteLoadingWidget(
+                    alignment: Alignment.topRight,
+                  )
+                : const SizedBox.shrink();
+          },
+        ),
+      ],
     );
   }
 }