import 'dart:ui'; import 'package:flutter/material.dart'; import '../styles/colors.dart'; import 'package:flutter/cupertino.dart'; import '../styles/totast.dart'; import '../model/PlayerInfo.dart'; import '../net/HttpManager.dart'; import '../net/Result.dart'; import '../model/HouseInfo.dart'; import '../model/GameInfo.dart'; import '../pages/RoomInfo.dart'; import 'package:flutter_redux/flutter_redux.dart'; import '../redux/AppState.dart'; class RecordList extends StatefulWidget { @override RecordListState createState() => RecordListState(); } class RecordListState extends State { ScrollController _mControll; List playerList = []; int currentPage = 1; bool isMore = false; Future getListPage() async { isMore = false; Toast.show(context, '加载中', -1, 'loading'); Result res = await HttpManager.get('playerInfo/page', data: {'userId': StoreProvider.of(context).state.userInfo.id, 'currentPage': currentPage, 'pageNumber': 20}); Toast.hide(); List list = playerList; if (currentPage == 1) { list = []; } if (res.success) { for (var item in res.data['pp']) { PlayerInfo tip = PlayerInfo.fromJson(item); list.add(tip); } if (res.data['page']['currentPage'] < res.data['page']['totalPage']) { isMore = true; } } else {} setState(() { playerList = list; }); } @override void initState() { super.initState(); _mControll = ScrollController(); _mControll.addListener(() { if (_mControll.position.pixels == _mControll.position.maxScrollExtent) { if (isMore) { currentPage++; getListPage(); } } }); Future.delayed(Duration.zero, () => getListPage()); } @override void dispose() { _mControll.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: PRIMARY_COLOR, title: Text('我的战绩'), centerTitle: true, elevation: 0, ), body: Container( color: BG_SUB_COLOR, child: RefreshIndicator( color: PRIMARY_COLOR, backgroundColor: Colors.white, onRefresh: () async { await Future.delayed(const Duration(seconds: 1)); currentPage = 1; getListPage(); }, child: ListView.builder( physics: AlwaysScrollableScrollPhysics(), controller: _mControll, itemCount: playerList.isNotEmpty ? playerList.length : 1, itemBuilder: (BuildContext context, int index) { if (playerList.isEmpty) { return Text( '还没有战绩快去比赛吧...', style: TextStyle(color: Colors.white30, fontSize: 13, height: 2), textAlign: TextAlign.center, ); } return houseItem(roomInfo: playerList[index].houseInfo, gameInfo: playerList[index].gameInfo, playerInfo: playerList[index]); })), )); } } class houseItem extends StatelessWidget { houseItem({Key key, this.roomInfo, this.gameInfo, this.playerInfo}) : super(key: key); final HouseInfo roomInfo; final GameInfo gameInfo; final PlayerInfo playerInfo; @override Widget build(BuildContext context) { List imageList = ['images/zhanji_icon_01.png', 'images/zhanji_icon_02.png', 'images/zhanji_icon_03.png', 'images/zhanji_icon_04.png']; String imageSrc = ''; if (playerInfo.houseRank != null) { if (playerInfo.houseRank < 4) { imageSrc = imageList[playerInfo.houseRank - 1]; } else { imageSrc = imageList[3]; } } String tishiStr = ''; if (playerInfo.statusFlag != null) { if (playerInfo.statusFlag == 6) { tishiStr = '未参加'; } else if (playerInfo.statusFlag < 4 || (roomInfo.statusFlag >= 2 && roomInfo.statusFlag < 4)) { tishiStr = '结算中'; } else if (playerInfo.statusFlag < 2) { tishiStr = '准备中'; } } if (roomInfo == null) { return Container(); } return Container( decoration: BoxDecoration( gradient: LinearGradient( colors: [Color(0xFF3F4261), Color(0xFF323456)], begin: Alignment.topCenter, end: Alignment.bottomCenter, ), border: Border(bottom: BorderSide(color: Colors.black, width: 1))), child: Material( color: Colors.transparent, child: InkWell( child: Padding( padding: EdgeInsets.all(15), child: Row( children: [ Image.network( gameInfo.icon, width: 48, height: 48, ), Container( width: 10, ), Expanded( flex: 1, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ LimitedBox( maxWidth: 170, child: Text( roomInfo.houseName, style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500), maxLines: 1, overflow: TextOverflow.ellipsis, ), ), Container( margin: EdgeInsets.only(left: 6), child: Image.network(roomInfo.houseLevel.icon, width: 14), ), Container( margin: EdgeInsets.only(left: 1), child: Text( roomInfo.houseLevel.levelName, style: TextStyle(color: Color(0xFFF9D881), fontSize: 9), )), ], ), Text( roomInfo.houseAbstract??'', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w400, color: Color(0xFF9BA0AE)), maxLines: 2, overflow: TextOverflow.ellipsis, ) ], ), ), imageSrc != '' ? Image.asset(imageSrc, width: 70) : Text(tishiStr, style: TextStyle(color: Colors.black38, fontSize: 14)) ], ), ), onTap: () { Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomInfo(roomId: roomInfo.id.toString()))); }, ), ), ); } }