寫一個Flutter彩票客戶端--開獎列表

數據來源 聚合數據網絡

項目用到的庫 rxdart + dio + bloc佈局

主要技術點:

  • 請求完數據的組合顯示(因爲聚合數據是每個彩種都是單個請求發);spa

  • 號碼的動態添加布局(遍歷數據動態添加布局數據,就像Android中動態addview同樣);code

  • rxdart + dio 的網絡請求;cdn

  • rxdart + bloc 的狀態管理;blog

  • Stack + Positoned + Offstage(隱藏顯示)Widget的使用接口


數據的組合: Future.wait([各個彩種的請求接口])

Future<Response> lottery(String lotteryId) {
    return _dio.get(Api.LOTTERY_QUERY, queryParameters: {
      "lottery_id": lotteryId,
      "lottery_no": "",
      "key": Api.KEY
    });
  }

Future queryLotteryList_() {
    Future<List<Response>> resp = Future.wait([
      lottery(Const.SSQ),
      lottery(Const.DLT),
      lottery(Const.QLC),
      lottery(Const.QXC),
      lottery(Const.PLS),
      lottery(Const.PLW),
      lottery(Const.FCSD),
    ]);
    return resp;
  }
複製代碼

號碼布局的實現(動態添加):

Container(
  padding: EdgeInsets.only(top: 9),
  child: Row(
    children: info.lotteryRes.split(',').map((number) {
      ++numberIndex;
      return Container(
        margin: EdgeInsets.only(right: 4),
        child: ClipOval(
          child: Container(
            width: 30,
            height: 30,
            color: Utils.getLotteryItemColor(
                numberIndex, info.lotteryId),
            child: Center(
              child: Text(
                number,
                style: TextStyle(
                    color: Colors.white, fontSize: 14),
              ),
            ),
          ),
        ),
      );
    }).toList(),
  ),
),
複製代碼

相關文章
相關標籤/搜索