RecordList.dart 7.1 KB

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