zoukankan      html  css  js  c++  java
  • flutter wrap 流式布局

    热门商品代码:

    import 'package:flutter/material.dart';

    import 'package:flutter_project/service/service_method.dart';
    import 'dart:convert';

    import 'package:flutter_screenutil/flutter_screenutil.dart';//使用json.decode
    class HotGoods extends StatefulWidget {
    HotGoods({Key key}) : super(key: key);
     
    @override
    _HotGoodsState createState() => _HotGoodsState();
    }


    class _HotGoodsState extends State<HotGoods> {
    int page = 1;
    List <Map> hotGoodsList = [];
    @override
    void initState() {
     
    super.initState();
    _getHotGoods();
     
    }
    //火爆专区接口
    void _getHotGoods(){
    getHotGoodSContent(page).then((val){
    var data = json.decode(val.toString());
    List<Map> newGoodList = (data['data'] as List).cast();//强转类型 从字符型转map
    setState(() {
    hotGoodsList.addAll(newGoodList);//将新数据newGoodList组合到老数据hotGoodsList,还是返回到老数据hotGoodsList
    page++;
    });
    });

    }

    Widget hotTitle = Container(
    margin: EdgeInsets.only(top: 10.0),//上间距
    padding: EdgeInsets.all(5.0),//内间距
    alignment: Alignment.center,
    decoration: BoxDecoration(
    border: Border(bottom:BorderSide( 0.5,color: Colors.black12)),
    color: Colors.white
    ),
    child: Text('火爆专区'),
    );
    //火爆专区内容 --- 流式布局
    Widget _wrapList(){
    if (hotGoodsList.length!=0) {//集合有数据
     
    List<Widget> listWidget = hotGoodsList.map((val){//把map集合数据 改成 widget 集合数据 .map 类似于 ForIn
    return InkWell(
    onTap: (){
    print('点击了火爆专区的商品');
    },
    child: Container(
    ScreenUtil().setWidth(372),
    padding: EdgeInsets.all(5.0),
    margin: EdgeInsets.only(bottom: 3.0),
    child: Column(//纵向布局
    children: <Widget>[
    Image.network(val['image'], ScreenUtil().setWidth(375),),
    Text(
    val['name'],
    overflow: TextOverflow.ellipsis,
    maxLines: 1,
    style: TextStyle(color: Colors.orange,fontSize: ScreenUtil().setSp(26)),//字号
    ),
    Row(//横向布局
    mainAxisAlignment: MainAxisAlignment.spaceEvenly,//横向布局 子控件平均分成两份
    children: <Widget>[
     
    Text('¥${val['mallPrice']}'),
    Text(
    '¥${val['price']}',
    style: TextStyle(color: Colors.grey,decoration: TextDecoration.lineThrough),
    )
    ],
     
    )
    ],
    ),
    ),
    );
     
    }).toList();
    return Wrap(
    spacing: 2,
    children: listWidget,
    );
    } else {
    return Text('火爆专区无数据');
    }

    }
     

    @override
    Widget build(BuildContext context) {
     
     
    return Container(
    child: Column(
    children: <Widget>[
    hotTitle,
    _wrapList()
    ],
    ),
    );
    }
    }
     
  • 相关阅读:
    [SDOI2011] 消防 (树的直径,尺取法)
    [HNOI2006]公路修建问题 (二分答案,并查集)
    P1875 佳佳的魔法药水 (最短路,DP)
    [SCOI2016] 背单词 (Trie 树,贪心)
    [USACO08DEC] 秘密消息Secret Message (Trie树)
    [HDU4745] Two Rabbits (区间DP)
    [HDU4362] Palindrome subsequence (区间DP)
    评价手心输入法
    软件工程个人作业12
    第12周进度条
  • 原文地址:https://www.cnblogs.com/pp-pping/p/12235880.html
Copyright © 2011-2022 走看看