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