Flutter之Flexible组件

/**
 * Flexible组件可以使Row、Column、Flex等子组件在主轴方向有填充可用空间的能力,但是不强制子组件填充可用空间。
 * Expanded组件可以使Row、Column、Flex等子组件在其主轴方向上展开并填充可用空间,是强制子组件填充可用空间。
  const Flexible({
    Key key,
    this.flex = 1,//组件占据剩余空间的比例
    this.fit = FlexFit.loose,
    @required Widget child,
    })
 */
body: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                Container(
                  margin: EdgeInsets.all(5.0),
                  child: Text("Flexible1"),
                  color: Colors.blue,
                ),
                Flexible(
                  flex: 10,
                  child: Container(
                    margin: EdgeInsets.all(5.0),
                    child: Text("Flexible"),
                    color: Colors.blue,
                  ),
                ),
                Flexible(
                  flex: 10,
                  child: Container(
                    margin: EdgeInsets.all(5.0),
                    child: Text("Flexible"),
                    color: Colors.blue,
                  ),
                ),
                Flexible(
                  flex: 10,
                  child: Container(
                    margin: EdgeInsets.all(5.0),
                    child: Text("Flexible"),
                    color: Colors.blue,
                  ),
                ),
                Container(
                  margin: EdgeInsets.all(5.0),
                  child: Text("Flexible1"),
                  color: Colors.blue,
                ),
              ],
            ),
            Row(
              children: <Widget>[
                Container(
                  margin: EdgeInsets.all(5.0),
                  child: Text("Flexible1"),
                  color: Colors.blue,
                ),
                Flexible(
                  flex: 1,
                  child: Container(
                    child: Text("Flexible2"),
                    color: Colors.blue,
                  ),
                ),
                Container(
                  margin: EdgeInsets.all(5.0),
                  child: Text("Flexible3"),
                  color: Colors.blue,
                ),
              ],
            ),
            Row(
              children: <Widget>[
                Container(
                  margin: EdgeInsets.all(5.0),
                  child: Text("Expanded1"),
                  color: Colors.blue,
                ),
                Expanded(
                  flex: 1,
                  child: Container(
                    child: Text("Expanded2"),
                    color: Colors.blue,
                  ),
                ),
                Container(
                  margin: EdgeInsets.all(5.0),
                  child: Text("Expanded3"),
                  color: Colors.blue,
                )
              ],
            ),
            Row(
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: Container(
                    margin: EdgeInsets.all(5.0),
                    child: Text("Expanded"),
                    color: Colors.blue,
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Container(
                    margin: EdgeInsets.all(5.0),
                    child: Text("Expanded"),
                    color: Colors.blue,
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Container(
                    margin: EdgeInsets.all(5.0),
                    child: Text("Expanded"),
                    color: Colors.blue,
                  ),
                ),
              ],
            )
          ],
        ),
图片发自简书App

码云地址:https://gitee.com/xgljh/Flutter.git

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容