SecondRoomInfo.dart 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_redux/flutter_redux.dart';
  4. import 'package:wanna_battle/model/HouseInfo.dart';
  5. import 'package:wanna_battle/redux/AppState.dart';
  6. import '../model/PlayerInfo.dart';
  7. import 'dart:async';
  8. import '../styles/totast.dart';
  9. import '../net/HttpManager.dart';
  10. import '../net/Result.dart';
  11. import '../styles/colors.dart';
  12. import 'package:flutter/cupertino.dart';
  13. import 'VideoPlayer.dart';
  14. import '../Constants.dart';
  15. class SecondPage extends StatefulWidget {
  16. SecondPage(this.houseInfo, {Key key, this.playerInfo}) : super(key: key);
  17. final HouseInfo houseInfo; // 用来储存传递过来的值
  18. final PlayerInfo playerInfo;
  19. @override
  20. SecondPageState createState() => SecondPageState();
  21. }
  22. class SecondPageState extends State<SecondPage> {
  23. List<PlayerInfo> joinList = [];
  24. int currentPage = 1;
  25. bool ismore = true;
  26. ScrollController _perController;
  27. //获取房间用户
  28. Future<void> getPlayerPage() async {
  29. ismore = false;
  30. Toast.show(context, '加载中', -1, 'loading');
  31. Result res = await HttpManager.get('playerInfo/rankPage', data: {'houseId': widget.houseInfo.id, 'currentPage': currentPage, 'pageNumber': 20});
  32. Toast.hide();
  33. List<PlayerInfo> list = joinList;
  34. if (res.success) {
  35. if (currentPage == 1) {
  36. list = [];
  37. }
  38. for (var item in res.data['pp']) {
  39. PlayerInfo jonPlayer = PlayerInfo.fromJson(item);
  40. list.add(jonPlayer);
  41. }
  42. if (res.data['page']['currentPage'] < res.data['page']['totalPage']) {
  43. ismore = true;
  44. }
  45. } else {}
  46. setState(() {
  47. joinList = list;
  48. });
  49. }
  50. @override
  51. void initState() {
  52. super.initState();
  53. _perController = ScrollController();
  54. currentPage = 1;
  55. Future.delayed(Duration.zero, () {
  56. getPlayerPage();
  57. _perController.addListener(() {
  58. if (_perController.position.pixels == _perController.position.maxScrollExtent) {
  59. if (ismore) {
  60. currentPage++;
  61. getPlayerPage();
  62. }
  63. }
  64. });
  65. });
  66. }
  67. @override
  68. void dispose() {
  69. super.dispose();
  70. _perController.dispose();
  71. }
  72. @override
  73. Widget build(BuildContext context) {
  74. return Column(
  75. children: <Widget>[
  76. Expanded(
  77. child: RefreshIndicator(
  78. color: PRIMARY_COLOR,
  79. backgroundColor: Colors.white,
  80. displacement: 10,
  81. onRefresh: () async {
  82. await Future.delayed(const Duration(seconds: 1));
  83. currentPage = 1;
  84. getPlayerPage();
  85. },
  86. child: Container(
  87. color: Color(0x1A000000),
  88. child: ListView.builder(
  89. physics: AlwaysScrollableScrollPhysics(),
  90. padding: EdgeInsets.only(top: 10),
  91. controller: _perController,
  92. itemCount: joinList.length + 1,
  93. itemBuilder: (BuildContext context, int index) {
  94. if (index < joinList.length) {
  95. return playerItem(joinList[index], index);
  96. } else {
  97. return Container(
  98. padding: EdgeInsets.all(15),
  99. child: Text(
  100. '其他人员正在火速赶来中...',
  101. style: TextStyle(color: Colors.white30),
  102. textAlign: TextAlign.center,
  103. ),
  104. );
  105. }
  106. }),
  107. ),
  108. ),
  109. ),
  110. widget.houseInfo.statusFlag == HouseStatus.SETTLEMENT && widget.playerInfo != null
  111. ? Container(
  112. height: 60,
  113. color: SUB_COLOR,
  114. padding: EdgeInsets.only(right: 15),
  115. child: Row(
  116. children: <Widget>[
  117. Container(
  118. width: 57,
  119. child: Center(
  120. child: Container(
  121. width: 22,
  122. height: 22,
  123. color: Color(0x33FFFFFF),
  124. child: Center(
  125. child: Text(
  126. widget.playerInfo?.houseRank?.toString() ?? '',
  127. style: TextStyle(color: Colors.white, fontSize: 12),
  128. ),
  129. ),
  130. ),
  131. ),
  132. ),
  133. Container(
  134. margin: EdgeInsets.only(right: 12),
  135. child: ClipOval(
  136. child: CachedNetworkImage(
  137. width: 36,
  138. height: 36,
  139. imageUrl: StoreProvider.of<AppState>(context).state.userInfo.icon,
  140. ),
  141. ),
  142. ),
  143. Expanded(
  144. flex: 1,
  145. child: Text(
  146. StoreProvider.of<AppState>(context).state.userInfo.nickname,
  147. style: TextStyle(
  148. color: PRIMARY_COLOR,
  149. fontSize: 14,
  150. ),
  151. maxLines: 1,
  152. overflow: TextOverflow.ellipsis,
  153. ),
  154. ),
  155. Container(
  156. margin: EdgeInsets.only(right: 3),
  157. child: Image.asset(
  158. 'images/icon_jifen_da.png',
  159. width: 20,
  160. ),
  161. ),
  162. Text(
  163. widget.playerInfo?.points?.toString() ?? '0',
  164. style: TextStyle(color: Colors.yellow, fontSize: 14, fontWeight: FontWeight.bold),
  165. )
  166. ],
  167. ),
  168. )
  169. : Container()
  170. ],
  171. );
  172. }
  173. Widget playerItem(PlayerInfo info, int index) {
  174. return Container(
  175. width: double.infinity,
  176. height: 60,
  177. color: BG_COLOR,
  178. padding: EdgeInsets.only(right: 15),
  179. margin: EdgeInsets.only(top: 1),
  180. child: Container(
  181. decoration: BoxDecoration(border: Border(bottom: BorderSide(width: 1, color: BG_SUB_COLOR, style: BorderStyle.solid))),
  182. child: Row(
  183. children: <Widget>[
  184. Container(
  185. width: 57,
  186. child: Center(
  187. child: widget.houseInfo.statusFlag == 4 && index < 3
  188. ? Image.asset(
  189. 'images/icon_paihangbang_0' + (index + 1).toString() + '.png',
  190. width: 32,
  191. )
  192. : Container(
  193. width: 22,
  194. height: 22,
  195. color: Color(0x33FFFFFF),
  196. child: Center(
  197. child: Text(
  198. (index + 1).toString(),
  199. style: TextStyle(color: Colors.white, fontSize: 12),
  200. ),
  201. ),
  202. ),
  203. ),
  204. ),
  205. Container(
  206. margin: EdgeInsets.only(right: 12),
  207. child: ClipOval(
  208. child: CachedNetworkImage(
  209. width: 36,
  210. height: 36,
  211. imageUrl: info?.userInfo?.icon ?? '',
  212. ),
  213. ),
  214. ),
  215. Expanded(
  216. flex: 1,
  217. child: Text(
  218. info?.userInfo?.nickname ?? '',
  219. style: TextStyle(
  220. color: Colors.white,
  221. fontSize: 14,
  222. ),
  223. maxLines: 1,
  224. overflow: TextOverflow.ellipsis,
  225. ),
  226. ),
  227. widget.houseInfo.statusFlag == 4 && index < 3 && info.video != '' && info.video != null
  228. ? SizedBox(
  229. width: 68,
  230. height: 24,
  231. child: OutlineButton(
  232. padding: EdgeInsets.all(0),
  233. borderSide: BorderSide(color: PRIMARY_COLOR),
  234. textColor: PRIMARY_COLOR,
  235. splashColor: PRIMARY_COLOR.withAlpha(50),
  236. child: Text('查看回放',
  237. style: TextStyle(
  238. fontSize: 12,
  239. )),
  240. onPressed: () {
  241. Navigator.push(context, CupertinoPageRoute(builder: (context) => VideoPlayerPage(videoUrl: info.video, fileType: 'netWork')));
  242. },
  243. ),
  244. )
  245. : Container(),
  246. ],
  247. ),
  248. ),
  249. );
  250. }
  251. }