浏览代码

Changed width of button to take size of it's child for SmallButton

ashilkn 2 年之前
父节点
当前提交
c9b8392663
共有 1 个文件被更改,包括 22 次插入4 次删除
  1. 22 4
      lib/ui/components/button_widget.dart

+ 22 - 4
lib/ui/components/button_widget.dart

@@ -13,6 +13,11 @@ enum ExecutionState {
   successful,
   successful,
 }
 }
 
 
+enum ButtonSize {
+  small,
+  large;
+}
+
 typedef FutureVoidCallback = Future<void> Function();
 typedef FutureVoidCallback = Future<void> Function();
 
 
 class ButtonWidget extends StatelessWidget {
 class ButtonWidget extends StatelessWidget {
@@ -21,12 +26,14 @@ class ButtonWidget extends StatelessWidget {
   final ButtonType buttonType;
   final ButtonType buttonType;
   final FutureVoidCallback? onTap;
   final FutureVoidCallback? onTap;
   final bool isDisabled;
   final bool isDisabled;
+  final ButtonSize buttonSize;
 
 
   ///setting this flag to true will make the button appear like how it would
   ///setting this flag to true will make the button appear like how it would
   ///on dark theme irrespective of the app's theme.
   ///on dark theme irrespective of the app's theme.
   final bool isInActionSheet;
   final bool isInActionSheet;
   const ButtonWidget({
   const ButtonWidget({
     required this.buttonType,
     required this.buttonType,
+    required this.buttonSize,
     this.icon,
     this.icon,
     this.labelText,
     this.labelText,
     this.onTap,
     this.onTap,
@@ -82,6 +89,7 @@ class ButtonWidget extends StatelessWidget {
       buttonStyle: buttonStyle,
       buttonStyle: buttonStyle,
       buttonType: buttonType,
       buttonType: buttonType,
       isDisabled: isDisabled,
       isDisabled: isDisabled,
+      buttonSize: buttonSize,
       onTap: onTap,
       onTap: onTap,
       labelText: labelText,
       labelText: labelText,
       icon: icon,
       icon: icon,
@@ -96,10 +104,12 @@ class LargeButtonChildWidget extends StatefulWidget {
   final String? labelText;
   final String? labelText;
   final IconData? icon;
   final IconData? icon;
   final bool isDisabled;
   final bool isDisabled;
+  final ButtonSize buttonSize;
   const LargeButtonChildWidget({
   const LargeButtonChildWidget({
     required this.buttonStyle,
     required this.buttonStyle,
     required this.buttonType,
     required this.buttonType,
     required this.isDisabled,
     required this.isDisabled,
+    required this.buttonSize,
     this.onTap,
     this.onTap,
     this.labelText,
     this.labelText,
     this.icon,
     this.icon,
@@ -153,7 +163,7 @@ class _LargeButtonChildWidgetState extends State<LargeButtonChildWidget> {
       onTapCancel: _shouldRegisterGestures ? _onTapCancel : null,
       onTapCancel: _shouldRegisterGestures ? _onTapCancel : null,
       child: AnimatedContainer(
       child: AnimatedContainer(
         duration: const Duration(milliseconds: 16),
         duration: const Duration(milliseconds: 16),
-        width: double.infinity,
+        width: widget.buttonSize == ButtonSize.large ? double.infinity : null,
         decoration: BoxDecoration(
         decoration: BoxDecoration(
           borderRadius: const BorderRadius.all(Radius.circular(4)),
           borderRadius: const BorderRadius.all(Radius.circular(4)),
           color: buttonColor,
           color: buttonColor,
@@ -197,6 +207,9 @@ class _LargeButtonChildWidgetState extends State<LargeButtonChildWidget> {
                         ],
                         ],
                       )
                       )
                     : Row(
                     : Row(
+                        mainAxisSize: widget.buttonSize == ButtonSize.large
+                            ? MainAxisSize.max
+                            : MainAxisSize.min,
                         mainAxisAlignment: MainAxisAlignment.center,
                         mainAxisAlignment: MainAxisAlignment.center,
                         children: [
                         children: [
                           widget.icon == null
                           widget.icon == null
@@ -227,9 +240,14 @@ class _LargeButtonChildWidgetState extends State<LargeButtonChildWidget> {
                         ],
                         ],
                       )
                       )
                 : executionState == ExecutionState.inProgress
                 : executionState == ExecutionState.inProgress
-                    ? EnteLoadingWidget(
-                        is20pts: true,
-                        color: loadingIconColor,
+                    ? Row(
+                        mainAxisSize: MainAxisSize.min,
+                        children: [
+                          EnteLoadingWidget(
+                            is20pts: true,
+                            color: loadingIconColor,
+                          ),
+                        ],
                       )
                       )
                     : executionState == ExecutionState.successful
                     : executionState == ExecutionState.successful
                         ? Icon(
                         ? Icon(