Flutter(十三)ConstrainedBox

2019-07-17  本文已影响0人  天色将变
属性
ConstrainedBox({
    Key key,
    @required this.constraints,
    Widget child,
  }) 
const BoxConstraints({
    this.minWidth = 0.0,
    this.maxWidth = double.infinity,
    this.minHeight = 0.0,
    this.maxHeight = double.infinity,
  });
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: ConstrainedBox(
//          constraints: BoxConstraints.expand(),//child尽可能大
//          constraints: BoxConstraints.tightFor(width: 120, height: 120), //指定宽高
//          constraints: BoxConstraints.tightForFinite(),// 指定宽高,但有默认值,无限大
          constraints: BoxConstraints(
              minWidth: 100, maxWidth: 300, minHeight: 100, maxHeight: 300),
          child: Container(
            color: Colors.blue,
            height: 10,
            width: 1000,
          )),
    );
  }
}

如上代码:

多个ConstraintedBox嵌套时,最内部的child要符合外层所有的条件。比如嵌套时minWidth=10,minWidth = 40,minWidth=60,那么minWidth=60为准。
欢迎添加我的微信号:zrf540592766
欢迎关注我的公众号:Flutter和Dart开发实践
让我们共同学习进步,It is never too late to learn!
image.png
上一篇下一篇

猜你喜欢

热点阅读