【发布时间】:2020-09-05 15:38:50
【问题描述】:
【问题讨论】:
-
请发布您的代码
标签: flutter dart flutter-cupertino
【问题讨论】:
标签: flutter dart flutter-cupertino
将其包裹在 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?
【讨论】:
将其包装在 Container() 中并从那里设置宽度和高度
【讨论】:
给你的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 小部件。
【讨论】: