我已经阅读了SizedBox
和 的文档LimitedBox
,并没有发现两者之间有任何实际区别。
任何人都可以举一个例子,当一个人可能会失败和其他工作时?
小智 11
所以我发现,LimitedBox
只有当孩子不受width/height
其父母约束时才可用。
并SizedBox
简单地创建一个给定的盒子,width/height
并且不允许孩子超出给定的尺寸。
例子: ( LimitedBox
)
@override
Widget build(BuildContext context) {
return Scaffold(
body: LimitedBox(
maxHeight: 50, // no impact because it's child `Text` width/height isn't unconstrained
child: Text(
"A",
style: TextStyle(fontSize: 200),
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
示例 ( SizedBox
)
@override
Widget build(BuildContext context) {
return Scaffold(
body: SizedBox(
height: 50, // has impact, it won't let Text to be of more than 50 logical pixels high
child: Text(
"A",
style: TextStyle(fontSize: 200),
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
注意:如果有人有更好的答案,我很乐意接受他们的答案。
归档时间: |
|
查看次数: |
6001 次 |
最近记录: |