RecordList.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. import 'dart:ui';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import '../styles/totast.dart';
  5. import '../model/PlayerInfo.dart';
  6. import '../net/HttpManager.dart';
  7. import '../net/Result.dart';
  8. import '../model/HouseInfo.dart';
  9. import 'package:flutter_redux/flutter_redux.dart';
  10. import '../redux/AppState.dart';
  11. import '../widget/HouseItem.dart';
  12. class RecordList extends StatefulWidget {
  13. @override
  14. RecordListState createState() => RecordListState();
  15. }
  16. class RecordListState extends State<RecordList> with SingleTickerProviderStateMixin {
  17. final List<Tab> myTabs = <Tab>[Tab(text: '我创建的'), Tab(text: '我加入的')];
  18. TabController _tabController;
  19. @override
  20. void initState() {
  21. super.initState();
  22. _tabController = TabController(length: myTabs.length, vsync: this);
  23. }
  24. @override
  25. void dispose() {
  26. super.dispose();
  27. _tabController.dispose();
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return Scaffold(
  32. appBar: AppBar(
  33. // backgroundColor: PRIMARY_COLOR,
  34. title:Text('我的战绩'),
  35. centerTitle: true,
  36. elevation: 0,
  37. ),
  38. body: Container(
  39. padding: EdgeInsets.only(top: 10),
  40. child: RecordInfo(1),
  41. color: Color(0xFF2B2B42),
  42. ));
  43. }
  44. }
  45. class RecordInfo extends StatefulWidget {
  46. int type;
  47. RecordInfo(this.type);
  48. @override
  49. RecordInfoState createState() => RecordInfoState();
  50. }
  51. class RecordInfoState extends State<RecordInfo> {
  52. ScrollController _mControll;
  53. List<PlayerInfo> playerList = [];
  54. List<HouseInfo> houseList = [];
  55. int currentPage = 1;
  56. bool isMore = false;
  57. Future<void> getHousePage() async {
  58. Result res = await HttpManager.get('houseInfo/page', data: {
  59. 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
  60. 'currentPage': currentPage,
  61. 'pageNumber': 20,
  62. 'orderByStr': 'status_flag_,asc'
  63. });
  64. Toast.hide();
  65. List<HouseInfo> list = houseList;
  66. if (currentPage == 1) {
  67. list = [];
  68. }
  69. if (res.success) {
  70. for (var item in res.data['pp']) {
  71. HouseInfo tip = HouseInfo.fromJson(item);
  72. list.add(tip);
  73. }
  74. if (res.data['page']['currentPage'] < res.data['page']['totalPage']) {
  75. isMore = true;
  76. }
  77. } else {}
  78. setState(() {
  79. houseList = list;
  80. });
  81. }
  82. Future<void> getListPage() async {
  83. isMore = false;
  84. Toast.show(context, '加载中', -1, 'loading');
  85. if (widget.type == 0) {
  86. getHousePage();
  87. return;
  88. }
  89. Result res = await HttpManager.get('playerInfo/page',
  90. data: {'userId': StoreProvider.of<AppState>(context).state.userInfo.id, 'currentPage': currentPage, 'pageNumber': 20});
  91. Toast.hide();
  92. List<PlayerInfo> list = playerList;
  93. if (currentPage == 1) {
  94. list = [];
  95. }
  96. if (res.success) {
  97. for (var item in res.data['pp']) {
  98. PlayerInfo tip = PlayerInfo.fromJson(item);
  99. list.add(tip);
  100. }
  101. if (res.data['page']['currentPage'] < res.data['page']['totalPage']) {
  102. isMore = true;
  103. }
  104. } else {}
  105. setState(() {
  106. playerList = list;
  107. });
  108. }
  109. @override
  110. void initState() {
  111. super.initState();
  112. _mControll = ScrollController();
  113. _mControll.addListener(() {
  114. if (_mControll.position.pixels == _mControll.position.maxScrollExtent) {
  115. if (isMore) {
  116. currentPage++;
  117. getListPage();
  118. }
  119. }
  120. });
  121. Future.delayed(Duration.zero, () => getListPage());
  122. }
  123. @override
  124. void dispose() {
  125. _mControll.dispose();
  126. super.dispose();
  127. }
  128. @override
  129. Widget build(BuildContext context) {
  130. return Scaffold(
  131. body: Container(
  132. color: Color(0xFF2B2B42),
  133. child: RefreshIndicator(
  134. color: ThemeData().primaryColor,
  135. backgroundColor: Colors.white,
  136. onRefresh: () async {
  137. await Future.delayed(const Duration(seconds: 1));
  138. },
  139. child: widget.type == 0
  140. ? ListView.builder(
  141. physics: AlwaysScrollableScrollPhysics(),
  142. controller: _mControll,
  143. itemCount: houseList.isNotEmpty ? houseList.length : 1,
  144. itemBuilder: (BuildContext context, int index) {
  145. if (houseList.isEmpty) {
  146. return Text(
  147. '还没有战绩快去比赛吧...',
  148. style: TextStyle(color: Colors.white30, fontSize: 13, height: 2),
  149. textAlign: TextAlign.center,
  150. );
  151. }
  152. return HouseItem(houseList[index],houseList[index].gameInfo);
  153. })
  154. : ListView.builder(
  155. physics: AlwaysScrollableScrollPhysics(),
  156. controller: _mControll,
  157. itemCount: playerList.isNotEmpty ? playerList.length : 1,
  158. itemBuilder: (BuildContext context, int index) {
  159. if (playerList.isEmpty) {
  160. return Text(
  161. '还没有战绩快去比赛吧...',
  162. style: TextStyle(color: Colors.white30, fontSize: 13, height: 2),
  163. textAlign: TextAlign.center,
  164. );
  165. }
  166. return HouseItem( playerList[index].houseInfo, playerList[index].gameInfo, playerInfo: playerList[index]);
  167. }),
  168. )),
  169. );
  170. }
  171. }
  172. // class houseItem extends StatelessWidget {
  173. // houseItem({Key key, this.roomInfo, this.gameInfo, this.playerInfo, this.type = 0}) : super(key: key);
  174. // final HouseInfo roomInfo;
  175. // final GameInfo gameInfo;
  176. // final PlayerInfo playerInfo;
  177. // final int type;
  178. // @override
  179. // Widget build(BuildContext context) {
  180. // List imageList = [
  181. // 'images/jiangpai_huangjin.png',
  182. // 'images/jiangpai_baiyin.png',
  183. // 'images/jiangpai_qingtong.png',
  184. // 'images/zhanji_icon_04.png',
  185. // 'images/jiangpai_bojin.png'
  186. // ];
  187. // String imageSrc = '';
  188. // String tishiStr = '';
  189. // Color tishiColor;
  190. // bool isImport = false;
  191. // if (playerInfo != null) {
  192. // if (playerInfo.medal != null) {
  193. // if (playerInfo.medal == 'platinum') {
  194. // imageSrc = imageList[4];
  195. // } else if (playerInfo.medal == 'gold') {
  196. // imageSrc = imageList[0];
  197. // } else if (playerInfo.medal == 'silver') {
  198. // imageSrc = imageList[1];
  199. // } else if (playerInfo.medal == 'bronze') {
  200. // imageSrc = imageList[2];
  201. // }
  202. // else if(playerInfo.rank!=null){
  203. // tishiStr='第${playerInfo.rank}名';
  204. // }
  205. // // if (playerInfo.houseRank < 4) {
  206. // // imageSrc = imageList[playerInfo.houseRank - 1];
  207. // // } else {
  208. // // imageSrc = imageList[3];
  209. // // }
  210. // }
  211. // if (playerInfo.statusFlag != null) {
  212. // if (playerInfo.statusFlag == 6) {
  213. // imageSrc = imageList[3];
  214. // } else if (playerInfo.statusFlag == 0) {
  215. // tishiStr = '未开始';
  216. // } else if (playerInfo.statusFlag == 2) {
  217. // tishiStr = '进行中';
  218. // } else if (playerInfo.statusFlag < 4 || (roomInfo.statusFlag >= 2 && roomInfo.statusFlag < 4)) {
  219. // tishiStr = '结算中';
  220. // }
  221. // }
  222. // } else {
  223. // if (roomInfo.statusFlag == 0) {
  224. // tishiStr = '未开始';
  225. // tishiColor = Theme.of(context).primaryColor;
  226. // } else if (roomInfo.statusFlag == 2) {
  227. // tishiStr = '进行中';
  228. // tishiColor = Color(0xFFA9AABA);
  229. // } else if (roomInfo.statusFlag == 4) {
  230. // tishiStr = '已结束';
  231. // tishiColor = Color(0xFF595B77);
  232. // } else {
  233. // tishiStr = '结算中';
  234. // tishiColor = Color(0xFF595B77);
  235. // }
  236. // }
  237. // if (roomInfo == null) {
  238. // return Container();
  239. // }
  240. // return Container(
  241. // decoration: BoxDecoration(
  242. // // gradient: LinearGradient(
  243. // // colors: [Color(0xFF3F4261), Color(0xFF323456)],
  244. // // begin: Alignment.topCenter,
  245. // // end: Alignment.bottomCenter,
  246. // // ),
  247. // color: Color(0xFF363759),
  248. // ),
  249. // child: Column(
  250. // children: <Widget>[
  251. // Material(
  252. // color: Colors.transparent,
  253. // child: InkWell(
  254. // child: Padding(
  255. // padding: EdgeInsets.all(15),
  256. // child: Row(
  257. // children: <Widget>[
  258. // Image.network(
  259. // gameInfo.icon,
  260. // width: 48,
  261. // height: 48,
  262. // ),
  263. // Container(
  264. // width: 10,
  265. // ),
  266. // Expanded(
  267. // flex: 1,
  268. // child: Column(
  269. // crossAxisAlignment: CrossAxisAlignment.start,
  270. // children: <Widget>[
  271. // Row(
  272. // children: <Widget>[
  273. // LimitedBox(
  274. // maxWidth: 170,
  275. // child: Text(
  276. // roomInfo.houseName,
  277. // style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500),
  278. // maxLines: 1,
  279. // overflow: TextOverflow.ellipsis,
  280. // ),
  281. // ),
  282. // Container(
  283. // width: 5,
  284. // ),
  285. // ScoreType(roomInfo.scoreType)
  286. // // Container(
  287. // // margin: EdgeInsets.only(left: 6),
  288. // // child: Image.network(roomInfo.houseLevel.icon,
  289. // // width: 14),
  290. // // ),
  291. // // Container(
  292. // // margin: EdgeInsets.only(left: 1),
  293. // // child: Text(
  294. // // roomInfo.houseLevel.levelName,
  295. // // style: TextStyle(
  296. // // color: Color(0xFFF9D881), fontSize: 9),
  297. // // )),
  298. // ],
  299. // ),
  300. // Text(
  301. // roomInfo.houseAbstract ?? '',
  302. // style: TextStyle(fontSize: 12, fontWeight: FontWeight.w400, color: Color(0xFF9BA0AE)),
  303. // maxLines: 2,
  304. // overflow: TextOverflow.ellipsis,
  305. // )
  306. // ],
  307. // ),
  308. // ),
  309. // imageSrc != ''
  310. // ? Image.asset(imageSrc)
  311. // : (type == 2
  312. // ? Text(tishiStr, style: TextStyle(color: isImport ? PRIMARY_COLOR : Colors.white54, fontSize: 14))
  313. // : Container(
  314. // color: tishiColor,
  315. // padding: EdgeInsets.symmetric(vertical: 4, horizontal: 9),
  316. // child: Text(
  317. // tishiStr,
  318. // style: TextStyle(color: Color(0xFF252532), fontSize: 12),
  319. // ),
  320. // ))
  321. // ],
  322. // ),
  323. // ),
  324. // onTap: () {
  325. // Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomInfo(roomId: roomInfo.id.toString())));
  326. // },
  327. // ),
  328. // ),
  329. // Container(
  330. // margin: EdgeInsets.symmetric(horizontal: 15),
  331. // height: 1,
  332. // color: Color(0xFF2B2B42),
  333. // )
  334. // ],
  335. // ),
  336. // );
  337. // }
  338. // }