6 Flutter UI 之 AspectRatio,Card,Wrap 组件

文章介绍了Flutter中的几个关键UI组件,包括AspectRatio用于保持子元素宽高比,Card组件创建具有阴影和圆角的卡片视图,ListView用于展示列表数据,以及如何结合AspectRatio显示图文列表。此外,还讲解了Wrap组件在实现流式布局中的应用。
摘要由CSDN通过智能技术生成

一  AspectRatio

根据设置调整子元素的child 的宽高比。

body: Container(
          // 固定外层宽度
          width: 200,
          child: AspectRatio(
              // 宽高为3 比 1
              aspectRatio: 3,
              child: Container(
                color: Colors.red,
              )),
        )

二 Card 组件

是卡片组件块,内容可以有大多数类型的Widget 组成,Card 具有圆角和阴影,这让他看起来又立体感。

 ListView(
          children: <Widget>[
            Card(
              margin: EdgeInsets.all(10),
              child: Column(children: <Widget>[
                ListTile(
                    title: Text("Name:Leonardo"),
                    subtitle: Text("Job:Famous Actor")),
                Divider(),
                ListTile(
                    title: Text("Address:China "),
                    subtitle: Text("Slogan:I will not make much difference"))
              ]),
            )
          ],
        )

三 图文列表

ListView(
            children: listData.map((value) {
          return Card(
            margin: EdgeInsets.all(10),
            child: Column(
              children: [
                // 第一部分 图片组件 包裹比例放大
                AspectRatio(
                  aspectRatio: 20 / 9,
                  child: Image.network(
                    value["imageUrl"],
                    fit: BoxFit.fill,
                  ),
                ),
                // 第二部分 文字
                ListTile(
                  title: Text(value["title"]),
                  subtitle: Text(value["author"]),
                )
              ],
            ),
          );
        }).toList())

四  wrap 组件

Wrap 组件可以实现流布局

Wrap(
          // 排列的方向
          direction: Axis.horizontal,
          // 主轴的对齐方式
          alignment: WrapAlignment.start,
          // 纵轴的对齐方式
          runAlignment: WrapAlignment.center,
          // 横向的距离
          spacing: 10,
          // 纵向的距离
          runSpacing: 20,

          children: [
            MyButton(
              title: "very big apple",
            ),
            MyButton(
              title: "orange",
            ),
            MyButton(
              title: "egg is egg",
            ),
            MyButton(
              title: "beef",
            ),
            MyButton(
              title: "strawberry",
            ),
          ],
        )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值