roomList.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. backgroundColor: PRIMARY_COLOR,
  87. title: Text('房间列表'),
  88. centerTitle: true,
  89. elevation: 0,
  90. ),
  91. body: RefreshIndicator(
  92. color: PRIMARY_COLOR,
  93. backgroundColor: Colors.white,
  94. onRefresh: () async {
  95. await Future.delayed(const Duration(seconds: 1));
  96. setState(() {
  97. currentPage = 1;
  98. });
  99. getRoomInfo();
  100. },
  101. child: Container(
  102. color: BG_COLOR,
  103. child: Stack(
  104. children: <Widget>[
  105. CustomScrollView(
  106. controller: _controller,
  107. physics: AlwaysScrollableScrollPhysics(),
  108. slivers: <Widget>[
  109. SliverToBoxAdapter(
  110. child: Container(
  111. height: 44,
  112. ),
  113. ),
  114. SliverFixedExtentList(
  115. itemExtent: ScreenUtil().setWidth(78),
  116. delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
  117. if(roomList.isEmpty){
  118. return Text('暂无数据',style: TextStyle(
  119. color: Colors.grey,
  120. fontSize: 13,
  121. height:3
  122. ),textAlign: TextAlign.center);
  123. }else if(index ==roomList.length){
  124. return Text('更多房间敬请期待...',style: TextStyle(
  125. color: Colors.grey,
  126. fontSize: 13,
  127. height:3
  128. ),textAlign: TextAlign.center);
  129. }
  130. return HouseItem(
  131. roomInfo: roomList[index],
  132. gameInfo:roomList[index].gameInfo
  133. );
  134. }, childCount: roomList.length+1),
  135. )
  136. ],
  137. ),
  138. _topWidget()
  139. ],
  140. ),
  141. ),
  142. ));
  143. }
  144. Widget _topWidget() {
  145. return Positioned(
  146. width: ScreenUtil().setWidth(375),
  147. height: 44,
  148. child: Container(
  149. padding: EdgeInsets.all(14),
  150. color: Color(0xFF3A3D5C),
  151. child: Row(
  152. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  153. children: <Widget>[_chooseGame(), _chooseHouseType(), _chooseLevel(), _chooseStatus()],
  154. ),
  155. ),
  156. );
  157. }
  158. //选择游戏
  159. Widget _chooseGame() {
  160. Map gameInfo = {};
  161. for (var item in gameList) {
  162. if (item['id'].toString() == gameId.toString()) {
  163. gameInfo = item;
  164. }
  165. }
  166. return Expanded(
  167. flex: 1,
  168. child: MyPopupMenuButton(
  169. initialValue: gameId,
  170. padding: EdgeInsets.all(0.0),
  171. child: Row(
  172. crossAxisAlignment: CrossAxisAlignment.center,
  173. mainAxisAlignment: MainAxisAlignment.center,
  174. children: <Widget>[
  175. Expanded(
  176. flex: 1,
  177. child: Text(
  178. gameInfo['gameName'],
  179. style: TextStyle(color: gameId != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
  180. overflow: TextOverflow.ellipsis,
  181. textAlign: TextAlign.center,
  182. ),
  183. ),
  184. Icon(
  185. Icons.keyboard_arrow_down,
  186. color: gameId != '' ? PRIMARY_COLOR : Colors.white,
  187. size: 18,
  188. ),
  189. ],
  190. ),
  191. onSelected: (value) {
  192. setState(() {
  193. gameId = value;
  194. });
  195. currentPage=1;
  196. getRoomInfo();
  197. },
  198. itemBuilder: (BuildContext context) {
  199. return gameList.map((choice) {
  200. return MyPopupMenuItem(
  201. child: Text(
  202. choice['gameName'],
  203. style: TextStyle(fontSize: 14),
  204. ),
  205. value: choice['id'].toString());
  206. }).toList();
  207. }),
  208. );
  209. }
  210. //选择等级
  211. Widget _chooseLevel() {
  212. Map levelInfo = {};
  213. for (var item in levelList) {
  214. if (item['id'].toString() == houseLevel.toString()) {
  215. levelInfo = item;
  216. }
  217. }
  218. return Expanded(
  219. flex: 1,
  220. child: MyPopupMenuButton(
  221. initialValue: houseLevel,
  222. padding: EdgeInsets.all(0.0),
  223. child: Row(
  224. crossAxisAlignment: CrossAxisAlignment.center,
  225. mainAxisAlignment: MainAxisAlignment.center,
  226. children: <Widget>[
  227. Expanded(
  228. flex: 1,
  229. child: Text(
  230. levelInfo['levelName'],
  231. style: TextStyle(color: houseLevel != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
  232. overflow: TextOverflow.ellipsis,
  233. textAlign: TextAlign.center,
  234. ),
  235. ),
  236. Icon(
  237. Icons.keyboard_arrow_down,
  238. color: houseLevel != '' ? PRIMARY_COLOR : Colors.white,
  239. size: 18,
  240. ),
  241. ],
  242. ),
  243. onSelected: (value) {
  244. setState(() {
  245. houseLevel = value;
  246. });
  247. currentPage=1;
  248. getRoomInfo();
  249. },
  250. itemBuilder: (BuildContext context) {
  251. return levelList.map((choice) {
  252. return MyPopupMenuItem(
  253. child: Text(
  254. choice['levelName'],
  255. style: TextStyle(fontSize: 14),
  256. ),
  257. value: choice['id'].toString());
  258. }).toList();
  259. }),
  260. );
  261. }
  262. //选择房间状态
  263. Widget _chooseHouseType() {
  264. Map typeInfo = {};
  265. for (var item in typeList) {
  266. if (item['val'] == houseType) {
  267. typeInfo = item;
  268. }
  269. }
  270. return Expanded(
  271. flex: 1,
  272. child: MyPopupMenuButton(
  273. initialValue: houseType,
  274. padding: EdgeInsets.all(0.0),
  275. child: Row(
  276. crossAxisAlignment: CrossAxisAlignment.center,
  277. mainAxisAlignment: MainAxisAlignment.center,
  278. children: <Widget>[
  279. Expanded(
  280. flex: 1,
  281. child: Text(
  282. typeInfo['name'],
  283. style: TextStyle(color: houseType != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
  284. overflow: TextOverflow.ellipsis,
  285. textAlign: TextAlign.center,
  286. ),
  287. ),
  288. Icon(
  289. Icons.keyboard_arrow_down,
  290. color: houseType != '' ? PRIMARY_COLOR : Colors.white,
  291. size: 18,
  292. ),
  293. ],
  294. ),
  295. onSelected: (value) {
  296. setState(() {
  297. houseType = value;
  298. });
  299. currentPage=1;
  300. getRoomInfo();
  301. },
  302. itemBuilder: (BuildContext context) {
  303. return typeList.map((choice) {
  304. return MyPopupMenuItem(
  305. child: Text(
  306. choice['name'],
  307. style: TextStyle(fontSize: 14),
  308. ),
  309. value: choice['val']);
  310. }).toList();
  311. }),
  312. );
  313. }
  314. //选择状态
  315. Widget _chooseStatus() {
  316. Map statusInfo = {};
  317. for (var item in statusList) {
  318. if (item['val'] == statusFlag) {
  319. statusInfo = item;
  320. }
  321. }
  322. return Expanded(
  323. flex: 1,
  324. child: MyPopupMenuButton(
  325. initialValue: statusFlag,
  326. padding: EdgeInsets.all(0.0),
  327. child: Row(
  328. crossAxisAlignment: CrossAxisAlignment.center,
  329. mainAxisAlignment: MainAxisAlignment.center,
  330. children: <Widget>[
  331. Expanded(
  332. flex: 1,
  333. child: Text(
  334. statusInfo['name'],
  335. style: TextStyle(color: statusFlag != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
  336. overflow: TextOverflow.ellipsis,
  337. textAlign: TextAlign.center,
  338. ),
  339. ),
  340. Icon(
  341. Icons.keyboard_arrow_down,
  342. color: statusFlag != '' ? PRIMARY_COLOR : Colors.white,
  343. size: 18,
  344. ),
  345. ],
  346. ),
  347. onSelected: (value) {
  348. setState(() {
  349. statusFlag = value;
  350. });
  351. currentPage=1;
  352. getRoomInfo();
  353. },
  354. itemBuilder: (BuildContext context) {
  355. return statusList.map((choice) {
  356. return MyPopupMenuItem(
  357. child: Text(
  358. choice['name'],
  359. style: TextStyle(fontSize: 14),
  360. ),
  361. value: choice['val']);
  362. }).toList();
  363. }),
  364. );
  365. }
  366. Future<void> getRoomInfo() async {
  367. Map<String, dynamic> data = {
  368. 'currentPage': currentPage,
  369. 'pageNumber': 20,
  370. };
  371. data['advancedQuery'] = '';
  372. if (gameId != '') {
  373. data['advancedQuery'] += 'AND_,gameId_,=_,' + gameId + '_;';
  374. }
  375. if (houseLevel != '') {
  376. data['advancedQuery'] += 'AND_,houseLevel_,=_,' + houseLevel + '_;';
  377. }
  378. if (houseType != '') {
  379. data['advancedQuery'] += 'AND_,houseType_,=_,' + houseType + '_;';
  380. }
  381. if (statusFlag != '') {
  382. data['advancedQuery'] += 'AND_,statusFlag_,=_,' + statusFlag + '_;';
  383. } else {
  384. data['statusStr'] = '0,4';
  385. }
  386. List<HouseInfo> _allList=roomList;
  387. if(currentPage==1){
  388. _allList=[];
  389. }
  390. Result res = await HttpManager.get('houseInfo/page', data: data);
  391. if (res.success && res.data['pp'] != null) {
  392. for (var item in res.data['pp']) {
  393. HouseInfo _temHouse=HouseInfo.fromJson(item);
  394. _allList.add(_temHouse);
  395. }
  396. if (res.data['page']['currentPage'] < res.data['page']['totalPage']) {
  397. scrollFlag = true;
  398. } else {
  399. scrollFlag = false;
  400. }
  401. } else {}
  402. setState(() {
  403. roomList=_allList;
  404. });
  405. // final response = await Dio().get(domain + 'houseInfo/page', data: data);
  406. // final res = json.decode(response.toString());
  407. // if (res['success']) {
  408. // for (var item in res['data']['pp']) {
  409. // setState(() {
  410. // roomList.add(item);
  411. // });
  412. // }
  413. // if (res['data']['page']['currentPage'] <
  414. // res['data']['page']['totalPage']) {
  415. // scrollFlag = true;
  416. // } else {
  417. // scrollFlag = false;
  418. // }
  419. // }
  420. }
  421. }