Flutter 图文列表的实现,抽离card的实现

2019/12/22 10:22:2 | 阅1592 来源:好空间网络 [打印] [关闭]
 

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      title: "tttttttttt",
      home: Scaffold(
        appBar: AppBar(
          title: Text("我是标题"),
        ),
        body: HomeContext(),
      ),
    );
  }
}

//自定义的Widget
class HomeContext extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ListView(
        children: <Widget>[
          ProductItem("Apple", "MacBooks Product",
              "https://i0.hdslb.com/bfs/archive/507dbb3c40187f55f8f68b859e6ff941f3c00968.jpg@1100w_484h_1c_100q.jpg"),
          ProductItem("Apple", "MacBooks Product",
              "https://i0.hdslb.com/bfs/archive/507dbb3c40187f55f8f68b859e6ff941f3c00968.jpg@1100w_484h_1c_100q.jpg"),
          ProductItem("Apple", "MacBooks Product",
              "https://i0.hdslb.com/bfs/archive/507dbb3c40187f55f8f68b859e6ff941f3c00968.jpg@1100w_484h_1c_100q.jpg"),
          ProductItem("Apple", "MacBooks Product",
              "https://i0.hdslb.com/bfs/archive/507dbb3c40187f55f8f68b859e6ff941f3c00968.jpg@1100w_484h_1c_100q.jpg"),
          ProductItem("Apple", "MacBooks Product",
              "https://i0.hdslb.com/bfs/archive/507dbb3c40187f55f8f68b859e6ff941f3c00968.jpg@1100w_484h_1c_100q.jpg"),
          ProductItem("Apple", "MacBooks Product",
              "https://i0.hdslb.com/bfs/archive/507dbb3c40187f55f8f68b859e6ff941f3c00968.jpg@1100w_484h_1c_100q.jpg"),
        ],
     
    );
  }
}

class ProductItem extends StatelessWidget {
  final String title;
  final String subtitle;
  final String imgurl;

  ProductItem(this.title, this.subtitle, this.imgurl);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      padding: EdgeInsets.all(15),
      margin: EdgeInsets.all(15),
      decoration: BoxDecoration(       
        border: Border.all(
          width: 1
        )
      ),
      child: Column(
        children: <Widget>[
          Text(
            title,
            style: TextStyle(fontSize: 22),
          ),
          Text(
            subtitle,
            style: TextStyle(fontSize: 18),
          ),
          SizedBox(
            height: 20,
          ),
          Image.network(imgurl)
        ],
      ),
    );
  }
}


放了个container 

里面设置了padding 和margin,然后设置了bordder的大小

container的child里放了个colum列,列里面才放了标题,副标题和图片

最后实现的效果


TIM图片20191222102148.png

经营许可证ICP:皖B2-20100052 公司邮箱:zcdnsz@jspkongjian.net
Copyright © 2004-2015, 安徽好空间网络科技有限公司 版权所有 , 本站素材部分来源于网络,如有侵权请告知删除。