【Flutter】Container设置对齐方式会填满父组件剩余空间

在使用Flex组件(Row、Column)时,使用Flexible嵌套Container,设置对齐方式会填满父组件剩余空间。

实例代码1

Dart 复制代码
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Flexible(
              child: Container(
                color: Colors.blue,
                // alignment: Alignment.center,
                padding: const EdgeInsets.all(8.0),
                child: const Text(
                  'You have pushed the button this many times:',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),

左图:注释// alignment: Alignment.center | 右图:不注释