Flutter minWidth和maxWidth 限制容器


对其子级施加其他(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,
    );
  }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM