gpt4 book ai didi

flutter - 我如何了解容器 'to be as small as possible'

转载 作者:IT王子 更新时间:2023-10-29 07:02:56 26 4
gpt4 key购买 nike

在Container.class中描述为'尽可能小',但是我试过没有 child 的Container,它充满了屏幕,所以我怎么理解尽可能小

class MyApp extends StatefulWidget {
@override
MappState createState() {
return MappState();
}

}


class MappState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'myApp',
home: Scaffold(
body: Container(color: Colors.red,),
),
);
}

}```

最佳答案

文档是 very clear about this :

Containers with no children try to be as big as possible unless the incoming constraints are unbounded, in which case they try to be as small as possible. Containers with children size themselves to their children. The width, height, and constraints arguments to the constructor override this.

无限约束是将宽度或高度设置为 double.infinity

没有 child -> '尽可能'

No child unbounded -> 'As small as possible'

我推荐你看this article ,它有一些带有图像的代码示例,说明了约束的这些行为。

关于flutter - 我如何了解容器 'to be as small as possible',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56615894/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com