RoomList.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import '../styles/colors.dart';
  4. import '../widget/RoomItem.dart';
  5. import '../widget/PopupButton.dart';
  6. import 'dart:ui';
  7. import '../net/HttpManager.dart';
  8. import '../net/Result.dart';
  9. import '../model/HouseInfo.dart';
  10. import '../model/GameInfo.dart';
  11. class RoomList extends StatefulWidget {
  12. @override
  13. RoomListState createState() => RoomListState();
  14. }
  15. class RoomListState extends State<RoomList> {
  16. List<HouseInfo> roomList = [];
  17. int currentPage = 1;
  18. ScrollController _controller;
  19. bool scrollFlag = true;
  20. String gameId = '';
  21. String houseLevel = '';
  22. String houseType = '';
  23. String statusFlag = '0';
  24. List gameList = [
  25. {'id': '', 'gameName': '全部游戏'}
  26. ];
  27. List levelList = [
  28. {'levelName': '全部等级', 'id': ''}
  29. ];
  30. List typeList = [
  31. {'name': '全部房间', 'val': ''},
  32. {'name': '普通房间', 'val': '0'},
  33. {'name': '官方房间', 'val': '1'}
  34. ];
  35. List statusList = [
  36. {'name': '不限状态', 'val': ''},
  37. {'name': '等待中', 'val': '0'},
  38. // {'name': '准备中', 'val': '1'},
  39. // {'name': '已经开始', 'val': '2'},
  40. // {'name': '正在结算', 'val': '3'},
  41. {'name': '结算完成', 'val': '4'}
  42. ];
  43. @override
  44. void initState() {
  45. super.initState();
  46. _controller = ScrollController();
  47. _controller.addListener(() {
  48. if (_controller.position.pixels == _controller.position.maxScrollExtent) {
  49. if (scrollFlag) {
  50. setState(() {
  51. currentPage++;
  52. });
  53. getRoomInfo();
  54. }
  55. }
  56. });
  57. Future.delayed(Duration.zero, () {
  58. getRoomInfo();
  59. getInfo();
  60. });
  61. }
  62. Future<void> getInfo() async {
  63. Result res = await HttpManager.get('gameInfo/all');
  64. if (res.success) {
  65. setState(() {
  66. gameList.addAll(res.data);
  67. });
  68. }
  69. Result res2 = await HttpManager.get('houseLevel/all');
  70. if (res2.success) {
  71. setState(() {
  72. levelList.addAll(res2.data);
  73. });
  74. }
  75. }
  76. @override
  77. void dispose() {
  78. super.dispose();
  79. _controller.dispose();
  80. }
  81. @override
  82. Widget build(BuildContext context) {
  83. ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
  84. return Scaffold(
  85. appBar: AppBar(
  86. title: Text('房间列表'),
  87. centerTitle: true,
  88. elevation: 0,
  89. ),
  90. body: RefreshIndicator(
  91. color: PRIMARY_COLOR,
  92. backgroundColor: Colors.white,
  93. onRefresh: () async {
  94. await Future.delayed(const Duration(seconds: 1));
  95. setState(() {
  96. currentPage = 1;
  97. });
  98. getRoomInfo();
  99. },
  100. child: Container(
  101. color: BG_COLOR,
  102. child: Stack(
  103. children: <Widget>[
  104. CustomScrollView(
  105. controller: _controller,
  106. physics: AlwaysScrollableScrollPhysics(),
  107. slivers: <Widget>[
  108. SliverToBoxAdapter(
  109. child: Container(
  110. height: 44,
  111. ),
  112. ),
  113. SliverFixedExtentList(
  114. itemExtent: ScreenUtil().setWidth(78),
  115. delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
  116. if (roomList.isEmpty) {
  117. return Text('暂无数据', style: TextStyle(color: Colors.grey, fontSize: 13, height: 3), textAlign: TextAlign.center);
  118. } else if (index == roomList.length) {
  119. return Text('更多房间敬请期待...', style: TextStyle(color: Colors.grey, fontSize: 13, height: 3), textAlign: TextAlign.center);
  120. }
  121. return HouseItem(roomInfo: roomList[index], gameInfo: roomList[index].gameInfo);
  122. }, childCount: roomList.length + 1),
  123. )
  124. ],
  125. ),
  126. _topWidget()
  127. ],
  128. ),
  129. ),
  130. ));
  131. }
  132. Widget _topWidget() {
  133. return Positioned(
  134. width: ScreenUtil().setWidth(375),
  135. height: 44,
  136. child: Container(
  137. padding: EdgeInsets.all(14),
  138. color: Color(0xFF3A3D5C),
  139. child: Row(
  140. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  141. children: <Widget>[_chooseGame(), _chooseHouseType(), _chooseLevel(), _chooseStatus()],
  142. ),
  143. ),
  144. );
  145. }
  146. //选择游戏
  147. Widget _chooseGame() {
  148. Map gameInfo = {};
  149. for (var item in gameList) {
  150. if (item['id'].toString() == gameId.toString()) {
  151. gameInfo = item;
  152. }
  153. }
  154. return Expanded(
  155. flex: 1,
  156. child: MyPopupMenuButton(
  157. initialValue: gameId,
  158. padding: EdgeInsets.all(0.0),
  159. child: Row(
  160. crossAxisAlignment: CrossAxisAlignment.center,
  161. mainAxisAlignment: MainAxisAlignment.center,
  162. children: <Widget>[
  163. Expanded(
  164. flex: 1,
  165. child: Text(
  166. gameInfo['gameName'],
  167. style: TextStyle(color: gameId != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.bold),
  168. overflow: TextOverflow.ellipsis,
  169. textAlign: TextAlign.center,
  170. ),
  171. ),
  172. Icon(
  173. Icons.keyboard_arrow_down,
  174. color: gameId != '' ? PRIMARY_COLOR : Colors.white,
  175. size: 18,
  176. ),
  177. ],
  178. ),
  179. onSelected: (value) {
  180. setState(() {
  181. gameId = value;
  182. });
  183. currentPage = 1;
  184. getRoomInfo();
  185. },
  186. itemBuilder: (BuildContext context) {
  187. return gameList.map((choice) {
  188. return MyPopupMenuItem(
  189. child: Text(
  190. choice['gameName'],
  191. style: TextStyle(fontSize: 14),
  192. ),
  193. value: choice['id'].toString());
  194. }).toList();
  195. }),
  196. );
  197. }
  198. //选择等级
  199. Widget _chooseLevel() {
  200. Map levelInfo = {};
  201. for (var item in levelList) {
  202. if (item['id'].toString() == houseLevel.toString()) {
  203. levelInfo = item;
  204. }
  205. }
  206. return Expanded(
  207. flex: 1,
  208. child: MyPopupMenuButton(
  209. initialValue: houseLevel,
  210. padding: EdgeInsets.all(0.0),
  211. child: Row(
  212. crossAxisAlignment: CrossAxisAlignment.center,
  213. mainAxisAlignment: MainAxisAlignment.center,
  214. children: <Widget>[
  215. Expanded(
  216. flex: 1,
  217. child: Text(
  218. levelInfo['levelName'],
  219. style: TextStyle(color: houseLevel != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.bold),
  220. overflow: TextOverflow.ellipsis,
  221. textAlign: TextAlign.center,
  222. ),
  223. ),
  224. Icon(
  225. Icons.keyboard_arrow_down,
  226. color: houseLevel != '' ? PRIMARY_COLOR : Colors.white,
  227. size: 18,
  228. ),
  229. ],
  230. ),
  231. onSelected: (value) {
  232. setState(() {
  233. houseLevel = value;
  234. });
  235. currentPage = 1;
  236. getRoomInfo();
  237. },
  238. itemBuilder: (BuildContext context) {
  239. return levelList.map((choice) {
  240. return MyPopupMenuItem(
  241. child: Text(
  242. choice['levelName'],
  243. style: TextStyle(fontSize: 14),
  244. ),
  245. value: choice['id'].toString());
  246. }).toList();
  247. }),
  248. );
  249. }
  250. //选择房间状态
  251. Widget _chooseHouseType() {
  252. Map typeInfo = {};
  253. for (var item in typeList) {
  254. if (item['val'] == houseType) {
  255. typeInfo = item;
  256. }
  257. }
  258. return Expanded(
  259. flex: 1,
  260. child: MyPopupMenuButton(
  261. initialValue: houseType,
  262. padding: EdgeInsets.all(0.0),
  263. child: Row(
  264. crossAxisAlignment: CrossAxisAlignment.center,
  265. mainAxisAlignment: MainAxisAlignment.center,
  266. children: <Widget>[
  267. Expanded(
  268. flex: 1,
  269. child: Text(
  270. typeInfo['name'],
  271. style: TextStyle(color: houseType != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.bold),
  272. overflow: TextOverflow.ellipsis,
  273. textAlign: TextAlign.center,
  274. ),
  275. ),
  276. Icon(
  277. Icons.keyboard_arrow_down,
  278. color: houseType != '' ? PRIMARY_COLOR : Colors.white,
  279. size: 18,
  280. ),
  281. ],
  282. ),
  283. onSelected: (value) {
  284. setState(() {
  285. houseType = value;
  286. });
  287. currentPage = 1;
  288. getRoomInfo();
  289. },
  290. itemBuilder: (BuildContext context) {
  291. return typeList.map((choice) {
  292. return MyPopupMenuItem(
  293. child: Text(
  294. choice['name'],
  295. style: TextStyle(fontSize: 14),
  296. ),
  297. value: choice['val']);
  298. }).toList();
  299. }),
  300. );
  301. }
  302. //选择状态
  303. Widget _chooseStatus() {
  304. Map statusInfo = {};
  305. for (var item in statusList) {
  306. if (item['val'] == statusFlag) {
  307. statusInfo = item;
  308. }
  309. }
  310. return Expanded(
  311. flex: 1,
  312. child: MyPopupMenuButton(
  313. initialValue: statusFlag,
  314. padding: EdgeInsets.all(0.0),
  315. child: Row(
  316. crossAxisAlignment: CrossAxisAlignment.center,
  317. mainAxisAlignment: MainAxisAlignment.center,
  318. children: <Widget>[
  319. Expanded(
  320. flex: 1,
  321. child: Text(
  322. statusInfo['name'],
  323. style: TextStyle(color: statusFlag != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.bold),
  324. overflow: TextOverflow.ellipsis,
  325. textAlign: TextAlign.center,
  326. ),
  327. ),
  328. Icon(
  329. Icons.keyboard_arrow_down,
  330. color: statusFlag != '' ? PRIMARY_COLOR : Colors.white,
  331. size: 18,
  332. ),
  333. ],
  334. ),
  335. onSelected: (value) {
  336. setState(() {
  337. statusFlag = value;
  338. });
  339. currentPage = 1;
  340. getRoomInfo();
  341. },
  342. itemBuilder: (BuildContext context) {
  343. return statusList.map((choice) {
  344. return MyPopupMenuItem(
  345. child: Text(
  346. choice['name'],
  347. style: TextStyle(fontSize: 14),
  348. ),
  349. value: choice['val']);
  350. }).toList();
  351. }),
  352. );
  353. }
  354. Future<void> getRoomInfo() async {
  355. Map<String, dynamic> data = {
  356. 'currentPage': currentPage,
  357. 'pageNumber': 20,
  358. };
  359. data['advancedQuery'] = '';
  360. if (gameId != '') {
  361. data['advancedQuery'] += 'AND_,gameId_,=_,' + gameId + '_;';
  362. }
  363. if (houseLevel != '') {
  364. data['advancedQuery'] += 'AND_,houseLevel_,=_,' + houseLevel + '_;';
  365. }
  366. if (houseType != '') {
  367. data['advancedQuery'] += 'AND_,houseType_,=_,' + houseType + '_;';
  368. }
  369. if (statusFlag != '') {
  370. data['advancedQuery'] += 'AND_,status_flag_,=_,' + statusFlag + '_;';
  371. } else {
  372. data['statusStr'] = '0,4';
  373. }
  374. List<HouseInfo> _allList = roomList;
  375. if (currentPage == 1) {
  376. _allList = [];
  377. }
  378. Result res = await HttpManager.get('houseInfo/page', data: data);
  379. if (res.success && res.data['pp'] != null) {
  380. for (var item in res.data['pp']) {
  381. HouseInfo _temHouse = HouseInfo.fromJson(item);
  382. _allList.add(_temHouse);
  383. }
  384. if (res.data['page']['currentPage'] < res.data['page']['totalPage']) {
  385. scrollFlag = true;
  386. } else {
  387. scrollFlag = false;
  388. }
  389. } else {}
  390. setState(() {
  391. roomList = _allList;
  392. });
  393. // final response = await Dio().get(domain + 'houseInfo/page', data: data);
  394. // final res = json.decode(response.toString());
  395. // if (res['success']) {
  396. // for (var item in res['data']['pp']) {
  397. // setState(() {
  398. // roomList.add(item);
  399. // });
  400. // }
  401. // if (res['data']['page']['currentPage'] <
  402. // res['data']['page']['totalPage']) {
  403. // scrollFlag = true;
  404. // } else {
  405. // scrollFlag = false;
  406. // }
  407. // }
  408. }
  409. }