RoomList.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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 '../widget/ITextInput.dart';
  11. import 'package:flutter_redux/flutter_redux.dart';
  12. import '../redux/AppState.dart';
  13. import 'dart:async';
  14. import 'package:flutter/cupertino.dart';
  15. class RoomList extends StatefulWidget {
  16. @override
  17. RoomListState createState() => RoomListState();
  18. }
  19. class RoomListState extends State<RoomList> {
  20. List<HouseInfo> roomList = [];
  21. int currentPage = 1;
  22. ScrollController _controller;
  23. bool scrollFlag = true;
  24. bool _showSearch = false;
  25. String gameId = '';
  26. String houseLevel = '';
  27. String houseType = '';
  28. String statusFlag = '';
  29. String searchKey = '';
  30. FocusNode _contentFocusNode = FocusNode();
  31. List gameList = [
  32. {'id': '', 'gameName': '全部游戏'}
  33. ];
  34. List levelList = [
  35. {'levelName': '全部等级', 'id': ''}
  36. ];
  37. List typeList = [
  38. {'name': '全部房间', 'val': ''},
  39. {'name': '普通房间', 'val': '0'},
  40. {'name': '官方房间', 'val': '1'}
  41. ];
  42. List statusList = [
  43. {'name': '不限状态', 'val': ''},
  44. {'name': '等待中', 'val': '0'},
  45. // {'name': '准备中', 'val': '1'},
  46. // {'name': '已经开始', 'val': '2'},
  47. // {'name': '正在结算', 'val': '3'},
  48. {'name': '结算完成', 'val': '4'}
  49. ];
  50. Future<void> search(String text) async {
  51. if (text != searchKey) {
  52. currentPage = 1;
  53. searchKey = text;
  54. statusFlag = '';
  55. houseLevel = '';
  56. houseType = '';
  57. getRoomInfo();
  58. }
  59. }
  60. @override
  61. void initState() {
  62. super.initState();
  63. _controller = ScrollController();
  64. _controller.addListener(() {
  65. // print('1111111');
  66. if (_controller.position.pixels == _controller.position.maxScrollExtent) {
  67. if (scrollFlag) {
  68. setState(() {
  69. currentPage++;
  70. });
  71. getRoomInfo();
  72. }
  73. }
  74. });
  75. Future.delayed(Duration.zero, () {
  76. getRoomInfo();
  77. getInfo();
  78. });
  79. }
  80. Future<void> getInfo() async {
  81. Result res = await HttpManager.get('gameInfo/all');
  82. if (res.success) {
  83. setState(() {
  84. gameList.addAll(res.data);
  85. });
  86. }
  87. Result res2 = await HttpManager.get('houseLevel/all');
  88. if (res2.success) {
  89. setState(() {
  90. levelList.addAll(res2.data);
  91. });
  92. }
  93. }
  94. Future<void> changeGame(BuildContext context) async {
  95. String sex = await showCupertinoModalPopup(
  96. context: context,
  97. builder: (BuildContext context) {
  98. return CupertinoActionSheet(
  99. title: Text('选择性别'),
  100. actions: <Widget>[
  101. CupertinoActionSheetAction(
  102. child: Text('男'),
  103. onPressed: () {
  104. Navigator.pop(context, '男');
  105. },
  106. ),
  107. CupertinoActionSheetAction(
  108. child: Text('女'),
  109. onPressed: () {
  110. Navigator.pop(context, '女');
  111. },
  112. )
  113. ],
  114. cancelButton: CupertinoDialogAction(
  115. child: const Text('取消'),
  116. onPressed: () {
  117. Navigator.pop(context);
  118. },
  119. ),
  120. );
  121. });
  122. }
  123. @override
  124. void dispose() {
  125. super.dispose();
  126. _controller.dispose();
  127. }
  128. @override
  129. Widget build(BuildContext context) {
  130. ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
  131. return Scaffold(
  132. appBar: !_showSearch
  133. ? AppBar(
  134. title: Text('房间列表'),
  135. centerTitle: true,
  136. elevation: 0,
  137. actions: <Widget>[
  138. GestureDetector(
  139. child: Image.asset('images/icon_sousuo.png'),
  140. onTap: () async {
  141. setState(() {
  142. _showSearch = true;
  143. });
  144. // String result = await Navigator.of(context).push(
  145. // PageRouteBuilder(
  146. // opaque: false,
  147. // transitionDuration: Duration(milliseconds: 300),
  148. // transitionsBuilder: (BuildContext context,
  149. // Animation<double> animation,
  150. // Animation<double> secondaryAnimation,
  151. // Widget child) {
  152. // return FadeTransition(
  153. // opacity: CurvedAnimation(
  154. // parent: animation, curve: Curves.linear),
  155. // child: child,
  156. // );
  157. // },
  158. // pageBuilder: (BuildContext context, _, __) {
  159. // return searchInput();
  160. // }));
  161. // if (result != '' || searchKey != '') {
  162. // search(result);
  163. // }
  164. },
  165. )
  166. ],
  167. )
  168. : null,
  169. body: RefreshIndicator(
  170. color: PRIMARY_COLOR,
  171. backgroundColor: Colors.white,
  172. onRefresh: () async {
  173. await Future.delayed(const Duration(seconds: 1));
  174. setState(() {
  175. currentPage = 1;
  176. });
  177. getRoomInfo();
  178. },
  179. child: Container(
  180. color: Color(0xFF363759),
  181. child: Stack(
  182. children: <Widget>[
  183. CustomScrollView(
  184. controller: _controller,
  185. physics: AlwaysScrollableScrollPhysics(),
  186. slivers: <Widget>[
  187. SliverToBoxAdapter(
  188. child: Container(
  189. height: _showSearch ? MediaQueryData.fromWindow(window).padding.top + 100 : 44,
  190. ),
  191. ),
  192. SliverFixedExtentList(
  193. itemExtent: roomList.isEmpty ? 300 : ScreenUtil().setWidth(78),
  194. delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
  195. if (roomList.isEmpty) {
  196. return Container(
  197. padding: EdgeInsets.only(top: 105),
  198. child: Column(
  199. children: <Widget>[
  200. Image.asset('images/icon_kong.png'),
  201. Text('暂时没有此房间哦~', style: TextStyle(fontSize: 14, color: Theme.of(context).primaryColor.withOpacity(0.3)))
  202. ],
  203. ),
  204. );
  205. } else if (index == roomList.length) {
  206. return Text('更多房间敬请期待...', style: TextStyle(color: Colors.grey, fontSize: 13, height: 3), textAlign: TextAlign.center);
  207. }
  208. return HouseItem(roomInfo: roomList[index], gameInfo: roomList[index].gameInfo);
  209. }, childCount: roomList.length + 1),
  210. )
  211. ],
  212. ),
  213. // _topWidget(),
  214. _filifter(context),
  215. _showSearch ? _searchInput() : Container()
  216. ],
  217. ),
  218. ),
  219. ));
  220. }
  221. Widget _filifter(BuildContext context) {
  222. Map gameInfo = {};
  223. for (var item in gameList) {
  224. if (item['id'].toString() == gameId.toString()) {
  225. gameInfo = item;
  226. }
  227. }
  228. return Positioned(
  229. top: _showSearch ? MediaQueryData.fromWindow(window).padding.top + 56 : 0,
  230. width: 375,
  231. height: 44,
  232. child: Container(
  233. color: Color(0xFF2B2B42),
  234. padding: EdgeInsets.only(left: 22, right: 20),
  235. child: Row(
  236. children: <Widget>[Text('筛选游戏', style: TextStyle(fontSize: 12, color: Colors.white54)), _chooseGame()],
  237. ),
  238. ),
  239. );
  240. }
  241. Widget _topWidget() {
  242. return Positioned(
  243. top: _showSearch ? MediaQueryData.fromWindow(window).padding.top + 56 : 0,
  244. width: ScreenUtil().setWidth(375),
  245. height: 44,
  246. child: Container(
  247. padding: EdgeInsets.all(14),
  248. color: Color(0xFF2B2B42),
  249. child: Row(
  250. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  251. children: <Widget>[_chooseGame(), _chooseHouseType(), _chooseLevel(), _chooseStatus()],
  252. ),
  253. ),
  254. );
  255. }
  256. //选择游戏
  257. Widget _chooseGame() {
  258. Map gameInfo = {};
  259. for (var item in gameList) {
  260. if (item['id'].toString() == gameId.toString()) {
  261. gameInfo = item;
  262. }
  263. }
  264. return Expanded(
  265. flex: 1,
  266. child: MyPopupMenuButton(
  267. initialValue: gameId,
  268. padding: EdgeInsets.all(0.0),
  269. child: Row(
  270. crossAxisAlignment: CrossAxisAlignment.center,
  271. mainAxisAlignment: MainAxisAlignment.center,
  272. children: <Widget>[
  273. Expanded(
  274. flex: 1,
  275. child: Text(
  276. gameInfo['gameName'],
  277. style: TextStyle(color: gameId != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
  278. overflow: TextOverflow.ellipsis,
  279. textAlign: TextAlign.right,
  280. ),
  281. ),
  282. Icon(
  283. Icons.keyboard_arrow_down,
  284. color: gameId != '' ? PRIMARY_COLOR : Colors.white,
  285. size: 18,
  286. ),
  287. ],
  288. ),
  289. onSelected: (value) {
  290. setState(() {
  291. gameId = value;
  292. });
  293. currentPage = 1;
  294. getRoomInfo();
  295. },
  296. itemBuilder: (BuildContext context) {
  297. return gameList.map((choice) {
  298. return MyPopupMenuItem(
  299. child: Text(
  300. choice['gameName'],
  301. style: TextStyle(fontSize: 14),
  302. ),
  303. value: choice['id'].toString());
  304. }).toList();
  305. }),
  306. );
  307. }
  308. //选择等级
  309. Widget _chooseLevel() {
  310. Map levelInfo = {};
  311. for (var item in levelList) {
  312. if (item['id'].toString() == houseLevel.toString()) {
  313. levelInfo = item;
  314. }
  315. }
  316. return Expanded(
  317. flex: 1,
  318. child: MyPopupMenuButton(
  319. initialValue: houseLevel,
  320. padding: EdgeInsets.all(0.0),
  321. child: Row(
  322. crossAxisAlignment: CrossAxisAlignment.center,
  323. mainAxisAlignment: MainAxisAlignment.center,
  324. children: <Widget>[
  325. Expanded(
  326. flex: 1,
  327. child: Text(
  328. levelInfo['levelName'],
  329. style: TextStyle(color: houseLevel != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
  330. overflow: TextOverflow.ellipsis,
  331. textAlign: TextAlign.center,
  332. ),
  333. ),
  334. Icon(
  335. Icons.keyboard_arrow_down,
  336. color: houseLevel != '' ? PRIMARY_COLOR : Colors.white,
  337. size: 18,
  338. ),
  339. ],
  340. ),
  341. onSelected: (value) {
  342. setState(() {
  343. houseLevel = value;
  344. });
  345. currentPage = 1;
  346. getRoomInfo();
  347. },
  348. itemBuilder: (BuildContext context) {
  349. return levelList.map((choice) {
  350. return MyPopupMenuItem(
  351. child: Text(
  352. choice['levelName'],
  353. style: TextStyle(fontSize: 14),
  354. ),
  355. value: choice['id'].toString());
  356. }).toList();
  357. }),
  358. );
  359. }
  360. //选择房间状态
  361. Widget _chooseHouseType() {
  362. Map typeInfo = {};
  363. for (var item in typeList) {
  364. if (item['val'] == houseType) {
  365. typeInfo = item;
  366. }
  367. }
  368. return Expanded(
  369. flex: 1,
  370. child: MyPopupMenuButton(
  371. initialValue: houseType,
  372. padding: EdgeInsets.all(0.0),
  373. child: Row(
  374. crossAxisAlignment: CrossAxisAlignment.center,
  375. mainAxisAlignment: MainAxisAlignment.center,
  376. children: <Widget>[
  377. Expanded(
  378. flex: 1,
  379. child: Text(
  380. typeInfo['name'],
  381. style: TextStyle(color: houseType != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
  382. overflow: TextOverflow.ellipsis,
  383. textAlign: TextAlign.center,
  384. ),
  385. ),
  386. Icon(
  387. Icons.keyboard_arrow_down,
  388. color: houseType != '' ? PRIMARY_COLOR : Colors.white,
  389. size: 18,
  390. ),
  391. ],
  392. ),
  393. onSelected: (value) {
  394. setState(() {
  395. houseType = value;
  396. });
  397. currentPage = 1;
  398. getRoomInfo();
  399. },
  400. itemBuilder: (BuildContext context) {
  401. return typeList.map((choice) {
  402. return MyPopupMenuItem(
  403. child: Text(
  404. choice['name'],
  405. style: TextStyle(fontSize: 14),
  406. ),
  407. value: choice['val']);
  408. }).toList();
  409. }),
  410. );
  411. }
  412. //选择状态
  413. Widget _chooseStatus() {
  414. Map statusInfo = {};
  415. for (var item in statusList) {
  416. if (item['val'] == statusFlag) {
  417. statusInfo = item;
  418. }
  419. }
  420. return Expanded(
  421. flex: 1,
  422. child: MyPopupMenuButton(
  423. initialValue: statusFlag,
  424. padding: EdgeInsets.all(0.0),
  425. child: Row(
  426. crossAxisAlignment: CrossAxisAlignment.center,
  427. mainAxisAlignment: MainAxisAlignment.center,
  428. children: <Widget>[
  429. Expanded(
  430. flex: 1,
  431. child: Text(
  432. statusInfo['name'],
  433. style: TextStyle(color: statusFlag != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
  434. overflow: TextOverflow.ellipsis,
  435. textAlign: TextAlign.center,
  436. ),
  437. ),
  438. Icon(
  439. Icons.keyboard_arrow_down,
  440. color: statusFlag != '' ? PRIMARY_COLOR : Colors.white,
  441. size: 18,
  442. ),
  443. ],
  444. ),
  445. onSelected: (value) {
  446. setState(() {
  447. statusFlag = value;
  448. });
  449. currentPage = 1;
  450. getRoomInfo();
  451. },
  452. itemBuilder: (BuildContext context) {
  453. return statusList.map((choice) {
  454. return MyPopupMenuItem(
  455. child: Text(
  456. choice['name'],
  457. style: TextStyle(fontSize: 14),
  458. ),
  459. value: choice['val']);
  460. }).toList();
  461. }),
  462. );
  463. }
  464. Future<void> getRoomInfo() async {
  465. Map<String, dynamic> data = {'currentPage': currentPage, 'pageNumber': 20, 'myUserId': StoreProvider.of<AppState>(context).state.userInfo.id};
  466. data['advancedQuery'] = '';
  467. if (gameId != '') {
  468. data['gameId'] += gameId;
  469. }
  470. // if (houseLevel != '') {
  471. // data['advancedQuery'] += 'AND_,houseLevel_,=_,' + houseLevel + '_;';
  472. // }
  473. // if (houseType != '') {
  474. // data['advancedQuery'] += 'AND_,houseType_,=_,' + houseType + '_;';
  475. // }
  476. // if (statusFlag != '') {
  477. // data['advancedQuery'] += 'AND_,statusFlag_,=_,' + statusFlag + '_;';
  478. // } else {
  479. // data['statusStr'] = '0,4';
  480. // }
  481. data['searchKey'] = searchKey;
  482. List<HouseInfo> _allList = roomList;
  483. if (currentPage == 1) {
  484. _allList = [];
  485. }
  486. if (StoreProvider.of<AppState>(context).state.userInfo.recommender != null) {
  487. data['recommender'] = StoreProvider.of<AppState>(context).state.userInfo.recommender;
  488. }
  489. print(data);
  490. // myUserId=84705&recommender=84702
  491. Result res = await HttpManager.get('houseInfo/page', data: data);
  492. if (res.success && res.data['pp'] != null) {
  493. for (var item in res.data['pp']) {
  494. HouseInfo _temHouse = HouseInfo.fromJson(item);
  495. _allList.add(_temHouse);
  496. }
  497. if (res.data['page']['currentPage'] < res.data['page']['totalPage']) {
  498. scrollFlag = true;
  499. } else {
  500. scrollFlag = false;
  501. }
  502. } else {}
  503. setState(() {
  504. roomList = _allList;
  505. });
  506. // final response = await Dio().get(domain + 'houseInfo/page', data: data);
  507. // final res = json.decode(response.toString());
  508. // if (res['success']) {
  509. // for (var item in res['data']['pp']) {
  510. // setState(() {
  511. // roomList.add(item);
  512. // });
  513. // }
  514. // if (res['data']['page']['currentPage'] <
  515. // res['data']['page']['totalPage']) {
  516. // scrollFlag = true;
  517. // } else {
  518. // scrollFlag = false;
  519. // }
  520. // }
  521. }
  522. Widget _searchInput() {
  523. return Positioned(
  524. child: Container(
  525. padding: EdgeInsets.only(top: MediaQueryData.fromWindow(window).padding.top, left: 15),
  526. color:Theme.of(context).primaryColor,
  527. height: MediaQueryData.fromWindow(window).padding.top + 56,
  528. child: Row(
  529. children: <Widget>[
  530. Expanded(
  531. flex: 1,
  532. child: Container(
  533. height: 34,
  534. decoration: BoxDecoration(
  535. color: Colors.white,
  536. borderRadius: BorderRadius.all(Radius.circular(100)),
  537. ),
  538. child: ITextField(
  539. focusNode: _contentFocusNode,
  540. autofocus: true,
  541. hintText: '输入房间名称/房间号/创建人Code',
  542. inputBorder: InputBorder.none,
  543. hintStyle: TextStyle(
  544. fontSize: 16,
  545. color: Color(0xFF727785),
  546. ),
  547. textStyle: TextStyle(color: Colors.black),
  548. contentPadding: EdgeInsets.symmetric(vertical: 4, horizontal: 19),
  549. fieldCallBack: (content) {
  550. search(content);
  551. },
  552. counterStyle: TextStyle(color: BG_SUB_COLOR, fontSize: 0),
  553. textInputAction: TextInputAction.search),
  554. ),
  555. ),
  556. InkWell(
  557. child: Container(
  558. padding: EdgeInsets.fromLTRB(16, 0, 15, 4),
  559. child: Text('取消', style: TextStyle(color: Colors.white, fontSize: 16)),
  560. ),
  561. onTap: () {
  562. setState(() {
  563. _showSearch = false;
  564. currentPage = 1;
  565. searchKey = '';
  566. statusFlag = '';
  567. houseLevel = '';
  568. houseType = '';
  569. getRoomInfo();
  570. });
  571. },
  572. )
  573. ],
  574. )),
  575. );
  576. }
  577. }