zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

Flutter minWidth和maxWidth 限制容器

flutter容器 限制
2023-09-14 08:58:44 时间

对其子级施加其他(minWidth,maxWidth,minHeight,maxHeight)约束

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          child: ConstrainedBox(
            constraints: BoxConstraints(
              minHeight: 50,
              minWidth: 50,
              // minWidth: double.infinity, // //宽度尽可能大
            ),
            child: _buildChild(
              width: 50 + 10.0,
              height: 40,
            ),
          ),
        ),
      ),
    );
  }

  Container _buildChild({
    double width,
    double height,
  }) {
    return Container(
      height: height,
      width: width,
      color: Colors.red,
    );
  }
}