【问题标题】:How to set width of CupertinoButton in Flutter?如何在 Flutter 中设置 CupertinoButton 的宽度?
【发布时间】:2020-09-05 15:38:50
【问题描述】:

我在这里遗漏了一些明显的东西吗? 在 CupertinoButton 按钮上设置 minSize 会设置宽度 和 高度(见图)。

如何只设置宽度?

提前致谢。

【问题讨论】:

  • 请发布您的代码

标签: flutter dart flutter-cupertino


【解决方案1】:

将其包裹在 SizedBox 中并设置宽度和高度。

例子

SizedBox(
   width: 500,
   height: 200
   child: CupertinoButton(
       onPressed: (){},
       child: Text("Click Me", style: TextStyle(color: Colors.white)),
       color: Colors.green
   )
)

注意:最佳做法是使用 SizedBox,因为它更有效,因为您只需要更改宽度和高度。

检查这个。 Flutter: SizedBox Vs Container, why use one instead of the other?

【讨论】:

    【解决方案2】:

    将其包装在 Container() 中并从那里设置宽度和高度

    【讨论】:

      【解决方案3】:

      给你的CupertinoButton 一个特定的width 和height。

      您可以执行以下操作之一:

      1) 将其包裹在 SizedBox 中并为其指定宽度和高度

      例如检查下面的代码:

       SizedBox(
         // set your width property here
         width: 100,
         // set your width property here
         height: 100
         child: CupertinoButton(
           ......  
         ),
      );
      

      2) 将其包裹在Container 中并为其指定宽度和高度

      例如检查下面的代码:

      Container(
         // set your width property here
         width: 100,
         // set your width property here
         height: 100
         child: CupertinoButton(
           ......  
         ),
      );
      

      注意:为了获得更好的性能,建议根据要使用的属性来选择小部件。如果您需要 Container 的某些属性,请使用 Container 小部件。

      如果您不需要Container 的大部分属性,请使用SizedBox 小部件。

      【讨论】:

        猜你喜欢
        • 2021-12-02
        • 2022-06-23
        • 2022-12-04
        • 2018-10-21
        • 2018-11-02
        • 1970-01-01
        • 2020-09-25
        • 1970-01-01
        • 2019-06-20
        相关资源
        最近更新 更多