Flutter组件学习七-Card组件

Flutter Card组件学习

1、Card

1.1、属性
属性说明
margin外边距,EdgeInsets.all(10)
child子组件
ShapeCard 的阴影效果,默认的阴影效果为圆角的 长方形边。
1.2、代码

实现ListView中包含 Card

lib/res/listData.dart中

List listData = [
  {
    "title": 'Candy Shop',
    "author": 'Mohamed Chahin',
    "imageUrl": 'https://www.itying.com/images/flutter/1.png',
    "detail":
        'hkjhxn gooe djkfldj n bjn hkalhjfsmx xxx  kfldjfdkl xxjlkj xxjdlkjfd lxjlkni h',
  },
  {
    "title": 'Alibaba Shop',
    "author": 'Alibaba',
    "imageUrl": 'https://www.itying.com/images/flutter/3.png',
    "detail":
        'hkjhxn gooe djkfldj n bjn hkalhjfsmx xxx  kfldjfdkl xxjlkj xxjdlkjfd lxjlkni h',
  },
  {
    "title": 'Candy Shop',
    "author": 'Mohamed Chahin',
    "imageUrl": 'https://www.itying.com/images/flutter/4.png',
    "detail":
        'hkjhxn gooe djkfldj n bjn hkalhjfsmx xxx  kfldjfdkl xxjlkj xxjdlkjfd lxjlkni h',
  },
  {
    "title": 'Tornado',
    "author": 'Mohamed Chahin',
    "imageUrl": 'https://www.itying.com/images/flutter/5.png',
    "detail":
        'hkjhxn gooe djkfldj n bjn hkalhjfsmx xxx  kfldjfdkl xxjlkj xxjdlkjfd lxjlkni h',
  },
  {
    "title": 'Undo',
    "author": 'Mohamed Chahin',
    "imageUrl": 'https://www.itying.com/images/flutter/6.png',
    "detail":
        'hkjhxn gooe djkfldj n bjn hkalhjfsmx xxx  kfldjfdkl xxjlkj xxjdlkjfd lxjlkni h',
  },
  {
    "title": 'white-dragon',
    "author": 'Mohamed Chahin',
    "imageUrl": 'https://www.itying.com/images/flutter/7.png',
    "detail":
        'hkjhxn gooe djkfldj n bjn hkalhjfsmx xxx  kfldjfdkl xxjlkj xxjdlkjfd lxjlkni h',
  },
  {
    "title": 'white-dragon',
    "author": 'Mohamed Chahin',
    "imageUrl": 'https://www.itying.com/images/flutter/7.png',
    "detail":
        'hkjhxn gooe djkfldj n bjn hkalhjfsmx xxx  kfldjfdkl xxjlkj xxjdlkjfd lxjlkni h',
  },
];

MyCardView

import 'package:flutter/material.dart';
//引用数据文件
import 'package:flutter_app/res/listData.dart';

class MyCardView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        Card(
          margin: EdgeInsets.all(10),
          child: Column(
            children: <Widget>[
              ListTile(
                  title: Text(
                    '小明',
                    style: TextStyle(fontSize: 26),
                  ),
                  subtitle: Text('java 工程师')),
              ListTile(
                  title: Text(
                '电话: xxxxxxxxx',
              )),
              ListTile(
                  title: Text(
                '住址: xxxxxxxxx',
              )),
            ],
          ),
        ),
        Card(
          margin: EdgeInsets.all(10),
          child: Column(
            children: <Widget>[
              ListTile(
                  title: Text(
                    '小明',
                    style: TextStyle(fontSize: 26),
                  ),
                  subtitle: Text('java 工程师')),
              ListTile(
                  title: Text(
                '电话: xxxxxxxxx',
              )),
              ListTile(
                  title: Text(
                '住址: xxxxxxxxx',
              )),
            ],
          ),
        ),
        Card(
          margin: EdgeInsets.all(10),
          child: Column(
            children: <Widget>[
              ListTile(
                  title: Text(
                    '小明',
                    style: TextStyle(fontSize: 26),
                  ),
                  subtitle: Text('java 工程师')),
              ListTile(
                  title: Text(
                '电话: xxxxxxxxx',
              )),
              ListTile(
                  title: Text(
                '住址: xxxxxxxxx',
              )),
            ],
          ),
        )
      ],
    );
  }
}

//List中使用Card显示一张图片,一个头像,一个title,一个subTitle
class MyCardView2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        Card(
          margin: EdgeInsets.all(10),
          child: Column(
            children: <Widget>[
              AspectRatio(
                aspectRatio: 20 / 9,
                child: Image.network(
                  "https://www.itying.com/images/flutter/3.png",
                  fit: BoxFit.cover,
                ),
              ),
              ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "https://www.itying.com/images/flutter/3.png"),
                ),
                title: Text("xxxxxx"),
                subtitle: Text("xxxxxxxx"),
              )
            ],
          ),
        )
      ],
    );
  }
}

// 动态加载ListView 中的数据
class MyCardView3 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    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['detail'],
                  // 设置超过一行后,使用。。。
                  overflow: TextOverflow.ellipsis,
                ),
              )
            ],
          ),
        );
      }).toList(),
    );
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值