请像我5一样解释一下:Flutter中MainAxisSize的用途是什么?

Pam*_*ela 6 android dart flutter

我很清楚 MainAxisSize 的效果,但我不明白它的目的。请像我5岁一样解释一下。谢谢。

供进一步参考:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Color(0xffEDE7F6),
        body: SafeArea(
          child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
            Container(
              height: 100,
              width: 100,
              color: Color(0xff9575CD),
              child: Text('Container 1'),
            ),
            Container(
              height: 100,
              width: 100,
              color: Colors.black45,
              child: Text('Container 2'),
            ),
            Container(
              height: 100,
              width: 100,
              color: Colors.black12,
              child: Text('Container 3'),
            ),
          ]),
        ),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

模拟器上的输出:

在此输入图像描述

w46*_*461 18

假设您有一个高度为 400 的容器,包裹在包含 3 行高度为 100 的列(由高度定义或由其中的内容固有定义),这会留下 100pt 的高度未使用。

MainAxisSize.max 表示,在列的项目之间分配所有空间,因此在行之间创建 50 的空间。

MainAxisSize.min 表示,将行挤压在一起,并在末尾(或开头或两端,取决于对齐方式)留下未使用的空间 (100)

  • 如果这有帮助,接受或赞成答案会很好:-) (2认同)