美文网首页Flutter学习日记Flutter
Flutter常用widget “Expanded”,“Flex

Flutter常用widget “Expanded”,“Flex

作者: 坑吭吭 | 来源:发表于2018-07-19 12:30 被阅读23次

    Expanded 这是个用来让子项具有伸缩能力的widget

    Expanded继承自Flexible,但是它们两个的区别并不大,看它们的构造方法:

    class Expanded extends Flexible {
      /// Creates a widget that expands a child of a [Row], [Column], or [Flex]
      /// expand to fill the available space in the main axis.
      const Expanded({
        Key key,
        int flex: 1,
        @required Widget child,
      }) : super(key: key, flex: flex, fit: FlexFit.tight, child: child);
    }
    
    class Flexible extends ParentDataWidget<Flex> {
      /// Creates a widget that controls how a child of a [Row], [Column], or [Flex]
      /// flexes.
      const Flexible({
        Key key,
        this.flex: 1,
        this.fit: FlexFit.loose,
        @required Widget child,
      }) : super(key: key, child: child);
        ……
    }
    

    可见它们两个的默认灵活系数是一样的,但是fit参数不同,Expanded是默认要占满分配的空间的,而Flexible则默认不需要

    相关文章

      网友评论

        本文标题:Flutter常用widget “Expanded”,“Flex

        本文链接:https://www.haomeiwen.com/subject/jaxtmftx.html