Flutter 物流頁面實現

Flutter 物流頁面實現

flutter 物流效果這塊實現比較少,而且效果都不是我想要的,就自己寫了一個簡單風格的物流頁面,有需要的同學可以參考下。數據來自於後臺接口。
原文鏈接:https://blog.csdn.net/weixin_44259356/article/details/106015770

效果

在這裏插入圖片描述

關鍵代碼

數據源

  _load() async {
    await WebService(context)
        .getLogistics("ZTO".toString(),73129268351637.toString());
    setState(() {
      Global.profile.logisticsMessage != null? logisticsMessage = Global.profile.logisticsMessage:showTextDialog(context,'獲取數據失敗');
      print(logisticsMessage);
    });
  }

List Widget數據整理

  List<Widget> logisticsListItem(context){
    List<Widget> logisticsList=new List<Widget>();
    int i=1;
    if(logisticsMessage!=null)
      for(int n= logisticsMessage["Traces"].length-1;n>=0;--n,++i)
        logisticsList.add(i==logisticsMessage["Traces"].length?menuListItem(context,logisticsMessage["Traces"][n],i,true):menuListItem(context,logisticsMessage["Traces"][n],i,false));
//順序
      /*    logisticsMessage["Traces"].forEach((item){
      ++i;
      logisticsList.add(i==logisticsMessage["Traces"].length?menuListItem(context,item,i,true):menuListItem(context,item,i,false));
    });*/

    logisticsList.length==0?logisticsList.add(Center(child: Text("暫無物流信息"))):print(logisticsList);
    return logisticsList;
  }

每一項item

  Widget menuListItem(context,value,i,bool) {
    double height=1;
    if(bool)
      height=0;
    return i==1 ?
    Container(
        width: MediaQuery.of(context).size.width,
        margin: EdgeInsets.only(top: 0.0, left: 0.0,bottom:0.0), //容器外填充
        padding: EdgeInsets.only(top: 15.0, left: 15.0,right:15.0,bottom:0), //容器內填充
        child: Card(
          margin:EdgeInsets.only(left:15.0,right: 15),
          elevation: 0,
          child:
          Column(
            crossAxisAlignment: CrossAxisAlignment
                .start,
            children: <Widget>[
              Row(
                children: <Widget>[
                  Container(
                    width: 80,
                    child: Text("${value['AcceptTime']}",
                      style: TextStyle(fontSize: 15.0,height: 1.28,color: Color(0xFF999999)),
                      maxLines:2,
                      textAlign: TextAlign.justify,
                      overflow: TextOverflow.visible,
                    ),
                  ),

                  Padding(
                      padding: const EdgeInsets.only(top: 26.0,left: 6.5,right: 6.5),
                      child:Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Image(
                            image: AssetImage("imgs/wlxq_icon_zhuangtai.png"),
                            height: 11,
                            width: 11,
                            fit: BoxFit.fill,
                          ),
                          SizedBox(
                            width: 1,
                            height: 28,
                            child: DecoratedBox(
                              decoration: BoxDecoration(color: Color(0xFFCCCCCC)),
                            ),
                          ),
                        ],
                      ),
                  ),

                  Container(
                    width: MediaQuery.of(context).size.width-165,
                    child: Text("${value['AcceptStation']}",
                      style: TextStyle(fontSize: 15.0,fontWeight: FontWeight.bold,height: 1.28),
                      maxLines:3,
                      textAlign: TextAlign.justify,
                      overflow: TextOverflow.visible,
                    ),
                  ),
                ],
              ),
              //垂直分割線
              Padding(
                //左邊添加像素補白
                padding: const EdgeInsets.only(left: 91.5),
                child: SizedBox(
                  width: 1,
                  height: height,
                  child: DecoratedBox(
                    decoration: BoxDecoration(color: Color(0xFFCCCCCC)),
                  ),
                ),
              ),

            ],
          ),
        ),
    )
        :
    Container(
      width: MediaQuery.of(context).size.width,
      margin: EdgeInsets.only(top: 0.0, left: 0.0,bottom:0.0), //容器外填充
      padding: EdgeInsets.only(top: 0, left: 15.0,right:15.0,bottom:0), //容器內填充
      child: Card(
        margin:EdgeInsets.only(left:15.0,right: 15),
        elevation: 0,
        child:
        Column(
          crossAxisAlignment: CrossAxisAlignment
              .start,
          children: <Widget>[
            Row(
              children: <Widget>[
                Container(
                  width: 80,
                  child: Text("${value['AcceptTime']}",
                    style: TextStyle(fontSize: 15.0,height: 1.28,color: Color(0xFF999999)),
                    maxLines:2,
                    textAlign: TextAlign.justify,
                    overflow: TextOverflow.visible,
                  ),
                ),

                Padding(
                  padding: height==0?EdgeInsets.only(bottom: 32,left: 10.0,right: 10.5):EdgeInsets.only(bottom: 0,left: 10.0,right: 10.5),
                  child:Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      SizedBox(
                        width: 1,
                        height: 32,
                        child: DecoratedBox(
                          decoration: BoxDecoration(color: Color(0xFFCCCCCC)),
                        ),
                      ),
                      Image(
                        image: AssetImage("imgs/wlxq_icon_quan.png"),
                        height: 4,
                        width: 4,
                        fit: BoxFit.fill,
                      ),
                      SizedBox(
                        width: 1,
                        height: height==0?0:32,
                        child: DecoratedBox(
                          decoration: BoxDecoration(color: Color(0xFFCCCCCC)),
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  width: MediaQuery.of(context).size.width-165,
                  child: Text("${value['AcceptStation']}",
                    style: TextStyle(fontSize: 15.0,height: 1.28,color: Color(0xFF999999)),
                    maxLines:3,
                    textAlign: TextAlign.justify,
                    overflow: TextOverflow.visible,
                  ),
                ),
              ],
            ),
            //垂直分割線
            Padding(
              //左邊添加像素補白
              padding: const EdgeInsets.only(left: 91.5),
              child: SizedBox(
                width: 1,
                height: height,
                child: DecoratedBox(
                  decoration: BoxDecoration(color: Color(0xFFCCCCCC)),
                ),
              ),
            ),

          ],
        ),
      ),
    );
  }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章