Flutter--卡片组件

AspectRatio组件

属性 释义
aspectRatio 宽高比(参考值)
AspectRatio使用
class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      width: 200,
      child: AspectRatio(
        aspectRatio: 2.0/1.0, //
        child: Container(
          color: Colors.red,
        ),
      ),
    );
  }
}

Card组件

属性 释义
margin 外边距
Shape Card的阴影效果,默认的阴影效果为圆角的长方形边

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ListView(
      children: <Widget>[
        Card(
          margin: EdgeInsets.all(10),
          child: Column(
            children: <Widget>[
              ListTile(
                title: Text("w", style: TextStyle(fontSize: 28),),
                subtitle: Text("wwwwwwwww"),
              ),
              Divider(),
              ListTile(
                title: Text("phone", style: TextStyle(fontSize: 28),),
                subtitle: Text("wwwwwwwww"),
              ),
            ],
          ),
        ),
        Card(
          margin: EdgeInsets.all(10),
          child: Column(
            children: <Widget>[
              ListTile(
                title: Text("w", style: TextStyle(fontSize: 28),),
                subtitle: Text("wwwwwwwww"),
              ),
              Divider(),
              ListTile(
                title: Text("phone", style: TextStyle(fontSize: 28),),
                subtitle: Text("wwwwwwwww"),
              ),
            ],
          ),
        ),
        Card(
          margin: EdgeInsets.all(10),
          child: Column(
            children: <Widget>[
              ListTile(
                title: Text("w", style: TextStyle(fontSize: 28),),
                subtitle: Text("wwwwwwwww"),
              ),
              Divider(),
              ListTile(
                title: Text("phone", style: TextStyle(fontSize: 28),),
                subtitle: Text("wwwwwwwww"),
              ),
            ],
          ),
        )
      ],
    );
  }
}

在这里插入图片描述

eg: 图文Card示例:

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ListView(
      children: listData.map((value){
        return Card(
          margin: EdgeInsets.all(10),
          child: Column(
            children: <Widget>[
              AspectRatio(
                aspectRatio: 20/9,
                child: Image.network(value["imageUrl"], fit: BoxFit.cover,),
              ),
              ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(value["imageUrl"]),
                ),
                title: Text(value["title"]),
                subtitle: Text(value["author"]),
              )
            ],
          ),
        );
    }).toList(),
    );
  }
}

在这里插入图片描述

发布了175 篇原创文章 · 获赞 56 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_39424143/article/details/104750974