Prechádzať zdrojové kódy

Made showing success state even if execution time < debounce time configurable

ashilkn 2 rokov pred
rodič
commit
87e42715c5

+ 17 - 3
lib/ui/components/menu_item_widget/menu_item_widget.dart

@@ -54,6 +54,8 @@ class MenuItemWidget extends StatefulWidget {
 
 
   final bool surfaceExecutionStates;
   final bool surfaceExecutionStates;
 
 
+  final bool alwaysShowSuccessState;
+
   const MenuItemWidget({
   const MenuItemWidget({
     required this.captionedTextWidget,
     required this.captionedTextWidget,
     this.isExpandable = false,
     this.isExpandable = false,
@@ -78,6 +80,7 @@ class MenuItemWidget extends StatefulWidget {
     this.isGestureDetectorDisabled = false,
     this.isGestureDetectorDisabled = false,
     this.showOnlyLoadingState = false,
     this.showOnlyLoadingState = false,
     this.surfaceExecutionStates = true,
     this.surfaceExecutionStates = true,
+    this.alwaysShowSuccessState = false,
     Key? key,
     Key? key,
   }) : super(key: key);
   }) : super(key: key);
 
 
@@ -197,10 +200,21 @@ class _MenuItemWidgetState extends State<MenuItemWidget> {
         },
         },
       ),
       ),
     );
     );
-    await widget.onTap
-        ?.call()
-        .onError((error, stackTrace) => _debouncer.cancelDebounce());
+    await widget.onTap?.call().then(
+      (value) {
+        widget.alwaysShowSuccessState
+            ? executionStateNotifier.value = ExecutionState.successful
+            : null;
+      },
+      onError: (error, stackTrace) => _debouncer.cancelDebounce(),
+    );
     _debouncer.cancelDebounce();
     _debouncer.cancelDebounce();
+    if (widget.alwaysShowSuccessState) {
+      Future.delayed(const Duration(seconds: 2), () {
+        executionStateNotifier.value = ExecutionState.idle;
+      });
+      return;
+    }
     if (executionStateNotifier.value == ExecutionState.inProgress) {
     if (executionStateNotifier.value == ExecutionState.inProgress) {
       if (widget.showOnlyLoadingState) {
       if (widget.showOnlyLoadingState) {
         executionStateNotifier.value = ExecutionState.idle;
         executionStateNotifier.value = ExecutionState.idle;