RecordList.dart 7.0 KB

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