RecordList.dart 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import 'package:flutter/material.dart';
  2. import '../styles/colors.dart';
  3. import 'dart:ui';
  4. import 'package:flutter/cupertino.dart';
  5. import '../styles/totast.dart';
  6. import '../model/PlayerInfo.dart';
  7. import '../styles/totast.dart';
  8. import '../net/HttpManager.dart';
  9. import '../net/Result.dart';
  10. import '../model/HouseInfo.dart';
  11. import '../model/GameInfo.dart';
  12. import '../pages/RoomInfo.dart';
  13. import 'package:flutter_redux/flutter_redux.dart';
  14. import '../redux/AppState.dart';
  15. class RecordList extends StatefulWidget {
  16. @override
  17. RecordListState createState() => RecordListState();
  18. }
  19. class RecordListState extends State<RecordList> {
  20. ScrollController _mControll;
  21. List<PlayerInfo> playerList = [];
  22. int currentPage = 1;
  23. bool isMore = false;
  24. void getListPage() async {
  25. isMore = false;
  26. Toast.show(context, '加载中', -1, 'loading');
  27. Result res = await HttpManager.get("playerInfo/page", data: {
  28. "userId": StoreProvider.of<AppState>(context).state.userInfo.id,
  29. "currentPage": currentPage,
  30. "pageNumber": 20
  31. });
  32. Toast.hide();
  33. List<PlayerInfo> list = playerList;
  34. if (currentPage == 1) {
  35. list = [];
  36. }
  37. if (res.success) {
  38. for (var item in res.data['pp']) {
  39. print(item['houseInfo']);
  40. PlayerInfo tip = PlayerInfo.fromJson(item);
  41. list.add(tip);
  42. }
  43. if (res.data['page']['currentPage'] < res.data['page']['totalPage']) {
  44. isMore = true;
  45. }
  46. } else {}
  47. setState(() {
  48. playerList = list;
  49. });
  50. print(res.data['pp']);
  51. }
  52. @override
  53. void initState() {
  54. super.initState();
  55. _mControll = ScrollController();
  56. _mControll.addListener(() {
  57. if (_mControll.position.pixels == _mControll.position.maxScrollExtent) {
  58. if (isMore) {
  59. currentPage++;
  60. getListPage();
  61. }
  62. }
  63. });
  64. Future.delayed(Duration(milliseconds: 100), () => getListPage());
  65. }
  66. @override
  67. void dispose() {
  68. _mControll.dispose();
  69. super.dispose();
  70. }
  71. @override
  72. Widget build(BuildContext context) {
  73. return new Scaffold(
  74. appBar: AppBar(
  75. backgroundColor: PRIMARY_COLOR,
  76. title: Text('我的战绩'),
  77. centerTitle: true,
  78. elevation: 0,
  79. ),
  80. body: Container(
  81. color: BG_SUB_COLOR,
  82. child: RefreshIndicator(
  83. color: PRIMARY_COLOR,
  84. backgroundColor: BG_COLOR,
  85. onRefresh: () async {
  86. await new Future.delayed(const Duration(seconds: 1));
  87. currentPage = 1;
  88. getListPage();
  89. },
  90. child: ListView.builder(
  91. physics: AlwaysScrollableScrollPhysics(),
  92. controller: _mControll,
  93. itemCount: playerList.length != 0 ? playerList.length : 1,
  94. itemBuilder: (BuildContext context, int index) {
  95. if (playerList.length == 0) {
  96. return Text(
  97. '还没有战绩快去比赛吧...',
  98. style: TextStyle(
  99. color: Colors.white30, fontSize: 13, height: 2),
  100. textAlign: TextAlign.center,
  101. );
  102. }
  103. return houseItem(
  104. roomInfo: playerList[index].houseInfo,
  105. gameInfo: playerList[index].gameInfo,
  106. playerInfo: playerList[index]);
  107. })),
  108. ));
  109. }
  110. }
  111. class houseItem extends StatelessWidget {
  112. houseItem({Key key, this.roomInfo, this.gameInfo, this.playerInfo})
  113. : super(key: key);
  114. final HouseInfo roomInfo;
  115. final GameInfo gameInfo;
  116. final PlayerInfo playerInfo;
  117. @override
  118. Widget build(BuildContext context) {
  119. List imageList = [
  120. 'images/zhanji_icon_01.png',
  121. 'images/zhanji_icon_02.png',
  122. 'images/zhanji_icon_03.png',
  123. 'images/zhanji_icon_04.png'
  124. ];
  125. String imageSrc = '';
  126. if (playerInfo.houseRank != null) {
  127. if (playerInfo.houseRank < 4) {
  128. imageSrc = imageList[playerInfo.houseRank - 1];
  129. } else {
  130. imageSrc = imageList[3];
  131. }
  132. }
  133. String tishiStr = '';
  134. if (playerInfo.statusFlag != null) {
  135. if (playerInfo.statusFlag == 6) {
  136. tishiStr = '未参加';
  137. } else if (playerInfo.statusFlag < 4||(roomInfo.statusFlag>=2&&roomInfo.statusFlag<4)) {
  138. tishiStr = '结算中';
  139. } else if (playerInfo.statusFlag < 2) {
  140. tishiStr = '准备中';
  141. }
  142. }
  143. if (roomInfo == null) {
  144. return Container();
  145. }
  146. return Container(
  147. decoration: BoxDecoration(
  148. gradient: LinearGradient(
  149. colors: [Color(0xFF3F4261), Color(0xFF323456)],
  150. begin: Alignment.topCenter,
  151. end: Alignment.bottomCenter,
  152. ),
  153. border: Border(bottom: BorderSide(color: Colors.black, width: 1))),
  154. child: Material(
  155. color: Colors.transparent,
  156. child: InkWell(
  157. child: Padding(
  158. padding: EdgeInsets.all(15),
  159. child: Row(
  160. children: <Widget>[
  161. Image.network(
  162. gameInfo.icon,
  163. width: 48,
  164. height: 48,
  165. ),
  166. Container(
  167. width: 10,
  168. ),
  169. Expanded(
  170. flex: 1,
  171. child: Column(
  172. crossAxisAlignment: CrossAxisAlignment.start,
  173. children: <Widget>[
  174. Row(
  175. children: <Widget>[
  176. LimitedBox(
  177. maxWidth: 170,
  178. child: Text(
  179. roomInfo.houseName,
  180. style: TextStyle(
  181. color: Colors.white,
  182. fontSize: 14,
  183. fontWeight: FontWeight.w500),
  184. maxLines: 1,
  185. overflow: TextOverflow.ellipsis,
  186. ),
  187. ),
  188. Container(
  189. margin: EdgeInsets.only(left: 6),
  190. child: Image.network(roomInfo.houseLevel.icon,
  191. width: 14),
  192. ),
  193. Container(
  194. margin: EdgeInsets.only(left: 1),
  195. child: Text(
  196. roomInfo.houseLevel.levelName,
  197. style: TextStyle(
  198. color: Color(0xFFF9D881), fontSize: 9),
  199. )),
  200. ],
  201. ),
  202. Text(
  203. roomInfo.houseAbstract,
  204. style: TextStyle(
  205. fontSize: 12,
  206. fontWeight: FontWeight.w400,
  207. color: Color(0xFF9BA0AE)),
  208. maxLines: 2,
  209. overflow: TextOverflow.ellipsis,
  210. )
  211. ],
  212. ),
  213. ),
  214. imageSrc != ''
  215. ? Image.asset(imageSrc, width: 70)
  216. : Text(tishiStr,
  217. style: TextStyle(color: Colors.black38, fontSize: 14))
  218. ],
  219. ),
  220. ),
  221. onTap: () {
  222. Navigator.push(
  223. context,
  224. new CupertinoPageRoute(
  225. builder: (context) =>
  226. new RoomInfo(roomId: roomInfo.id.toString())));
  227. },
  228. ),
  229. ),
  230. );
  231. }
  232. }