RecordList.dart 13 KB

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