GridView - flutter

GridView 格式

GridView.count(
        crossAxisCount:2, // 一共有几列
        mainAxisSpacing: 10, //横向格间距
        crossAxisSpacing: 10, //竖向格间距

        children: [
          Container(
            child: Column(
              children: [
                Image.network(
                    "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2767608770,826089718&fm=26&gp=0.jpg",
                    width: 190,
                    // height: 150,
                    fit: BoxFit.cover,
                ),
                SizedBox(height: 60,),
                Text("what are you doing?"),
              ],
            ),
          ),
          Container(
            child: Text("what are you doing? 2"),
            decoration: BoxDecoration(
              color: Colors.blue
            ),
          ),
          Container(
            child: Text("what are you doing? 3" ),
            decoration: BoxDecoration(
              color: Colors.pink
            ),
          ),
          Container(
            child: Text("what are you doing? 4" ),
            decoration: BoxDecoration(
              color: Colors.green
            ),
          ),
        ],
    );

GridView builder

class HomeContent extends StatelessWidget {
  var list = [
    {"title": "a", "age": 1},
    {"title": "b", "age": 2},
    {"title": "c", "age": 3},
    {"title": "d", "age": 4},

  ];

  Widget _getData(context, index) {
    return Column(
                  children: [
                    Image.network(
                        "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2767608770,826089718&fm=26&gp=0.jpg",
                        width: 190,
                        // height: 150,
                        fit: BoxFit.cover,
                    ),

                    Text(this.list[index]["title"].toString() + ": " + this.list[index]["age"].toString()),
                  ],
                );

  }

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2, // 一共有几列
        mainAxisSpacing: 10, //横向格间距
        crossAxisSpacing: 10, //竖向格间距
        childAspectRatio: 1, //每个column的宽高比
      ),
      itemCount: this.list.length,
      itemBuilder: this._getData,
    );
    
  }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值