浏览代码

ButtonWidget: Support for showing progressStatus

Neeraj Gupta 2 年之前
父节点
当前提交
dff1e29526
共有 1 个文件被更改,包括 34 次插入0 次删除
  1. 34 0
      lib/ui/components/button_widget.dart

+ 34 - 0
lib/ui/components/button_widget.dart

@@ -60,6 +60,12 @@ class ButtonWidget extends StatelessWidget {
   ///This should be set to true if the alert which uses this button needs to
   ///return the Button's action.
   final bool isInAlert;
+
+  /// progressStatus can be used to display information about the action
+  /// progress when ExecutionState is in Progress.
+  // when
+  final ValueNotifier<String>? progressStatus;
+
   const ButtonWidget({
     required this.buttonType,
     this.buttonSize = ButtonSize.large,
@@ -72,6 +78,7 @@ class ButtonWidget extends StatelessWidget {
     this.isInAlert = false,
     this.iconColor,
     this.shouldSurfaceExecutionStates = true,
+    this.progressStatus,
     super.key,
   });
 
@@ -137,6 +144,7 @@ class ButtonWidget extends StatelessWidget {
       icon: icon,
       buttonAction: buttonAction,
       shouldSurfaceExecutionStates: shouldSurfaceExecutionStates,
+      progressStatus: progressStatus,
     );
   }
 }
@@ -152,6 +160,8 @@ class ButtonChildWidget extends StatefulWidget {
   final ButtonAction? buttonAction;
   final bool isInAlert;
   final bool shouldSurfaceExecutionStates;
+  final ValueNotifier<String>? progressStatus;
+
   const ButtonChildWidget({
     required this.buttonStyle,
     required this.buttonType,
@@ -159,6 +169,7 @@ class ButtonChildWidget extends StatefulWidget {
     required this.buttonSize,
     required this.isInAlert,
     required this.shouldSurfaceExecutionStates,
+    this.progressStatus,
     this.onTap,
     this.labelText,
     this.icon,
@@ -177,14 +188,17 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {
   late TextStyle labelStyle;
   late Color checkIconColor;
   late Color loadingIconColor;
+  ValueNotifier<String>? progressStatus;
 
   ///This is used to store the width of the button in idle state (small button)
   ///to be used as width for the button when the loading/succes states comes.
   double? widthOfButton;
   final _debouncer = Debouncer(const Duration(milliseconds: 300));
   ExecutionState executionState = ExecutionState.idle;
+
   @override
   void initState() {
+    progressStatus = widget.progressStatus;
     checkIconColor = widget.buttonStyle.checkIconColor ??
         widget.buttonStyle.defaultIconColor;
     loadingIconColor = widget.buttonStyle.defaultIconColor;
@@ -203,6 +217,7 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {
       iconColor = widget.buttonStyle.defaultIconColor;
       labelStyle = widget.buttonStyle.defaultLabelStyle;
     }
+
     super.initState();
   }
 
@@ -315,6 +330,21 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {
                             mainAxisAlignment: MainAxisAlignment.center,
                             mainAxisSize: MainAxisSize.min,
                             children: [
+                              progressStatus == null
+                                  ? const SizedBox.shrink()
+                                  : ValueListenableBuilder<String>(
+                                      valueListenable: progressStatus!,
+                                      builder: (
+                                        BuildContext context,
+                                        String value,
+                                        Widget? child,
+                                      ) {
+                                        return Text(
+                                          value,
+                                          style: lightTextTheme.smallBold,
+                                        );
+                                      },
+                                    ),
                               EnteLoadingWidget(
                                 is20pts: true,
                                 color: loadingIconColor,
@@ -342,6 +372,10 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {
   bool get _shouldRegisterGestures =>
       !widget.isDisabled && executionState == ExecutionState.idle;
 
+  void onTapExternal() async {
+    return _onTap();
+  }
+
   void _onTap() async {
     if (widget.onTap != null) {
       _debouncer.run(