SecondRoomInfo.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import 'package:flutter/material.dart';
  2. import '../model/PlayerInfo.dart';
  3. import 'dart:async';
  4. import '../styles/totast.dart';
  5. import '../net/HttpManager.dart';
  6. import '../net/Result.dart';
  7. import '../styles/colors.dart';
  8. import 'package:flutter/cupertino.dart';
  9. import 'VideoPlayer.dart';
  10. class SecondPage extends StatefulWidget {
  11. SecondPage({Key key, this.roomId, this.status}) : super(key: key);
  12. final String roomId; // 用来储存传递过来的值
  13. final int status;
  14. @override
  15. SecondPageState createState() => SecondPageState();
  16. }
  17. class SecondPageState extends State<SecondPage> {
  18. List<PlayerInfo> joinList = [];
  19. int currentPage = 1;
  20. bool ismore = true;
  21. ScrollController _perController;
  22. List jiangpaiImg = ['images/jiangpai_huangjin.png', 'images/jiangpai_baiyin.png', 'images/jiangpai_qingtong.png', 'images/jiangpai_bojin.png'];
  23. //获取房间用户
  24. Future<void> getPlayerPage() async {
  25. ismore = false;
  26. Toast.show(context, '加载中', -1, 'loading');
  27. Result res = await HttpManager.get('playerInfo/rankPage', data: {'houseId': widget.roomId, 'currentPage': currentPage, 'pageNumber': 20});
  28. Toast.hide();
  29. List<PlayerInfo> list = joinList;
  30. if (currentPage == 1) {
  31. list = [];
  32. }
  33. if (res.success) {
  34. print(res.data['pp']);
  35. for (var item in res.data['pp']) {
  36. PlayerInfo jonPlayer = PlayerInfo.fromJson(item);
  37. list.add(jonPlayer);
  38. }
  39. if (res.data['page']['currentPage'] < res.data['page']['totalPage']) {
  40. ismore = true;
  41. }
  42. } else {}
  43. setState(() {
  44. joinList = list;
  45. });
  46. }
  47. @override
  48. void initState() {
  49. super.initState();
  50. _perController = ScrollController();
  51. currentPage = 1;
  52. Future.delayed(Duration.zero, () {
  53. getPlayerPage();
  54. _perController.addListener(() {
  55. if (_perController.position.pixels == _perController.position.maxScrollExtent) {
  56. if (ismore) {
  57. currentPage++;
  58. getPlayerPage();
  59. }
  60. }
  61. });
  62. });
  63. }
  64. @override
  65. void dispose() {
  66. super.dispose();
  67. _perController.dispose();
  68. }
  69. @override
  70. Widget build(BuildContext context) {
  71. return RefreshIndicator(
  72. color: PRIMARY_COLOR,
  73. backgroundColor: Colors.white,
  74. displacement: 10,
  75. onRefresh: () async {
  76. await Future.delayed(const Duration(seconds: 1));
  77. currentPage = 1;
  78. getPlayerPage();
  79. },
  80. child: ListView.builder(
  81. physics: AlwaysScrollableScrollPhysics(),
  82. controller: _perController,
  83. itemCount: joinList.length + 1,
  84. itemBuilder: (BuildContext context, int index) {
  85. if (index < joinList.length) {
  86. return PersonItem(joinList[index], index);
  87. } else {
  88. return Container(
  89. padding: EdgeInsets.all(15),
  90. child: Text(
  91. '其他人员正在火速赶来中...',
  92. style: TextStyle(color: Colors.white30),
  93. textAlign: TextAlign.center,
  94. ),
  95. );
  96. }
  97. }),
  98. );
  99. }
  100. Widget PersonItem(PlayerInfo info, int index) {
  101. String img = '';
  102. if (info.medal == 'platinum') {
  103. img = jiangpaiImg[3];
  104. } else if (info.medal == 'gold') {
  105. img = jiangpaiImg[0];
  106. } else if (info.medal == 'silver') {
  107. img = jiangpaiImg[1];
  108. } else if (info.medal == 'bronze') {
  109. img = jiangpaiImg[2];
  110. }
  111. return Container(
  112. width: double.infinity,
  113. height: 60,
  114. color: Color(0xFF2B2B42),
  115. margin: EdgeInsets.only(top: index == 0 ? 10 : 0),
  116. padding: EdgeInsets.only(left: 15, right: 15),
  117. child: Container(
  118. decoration: BoxDecoration(border: Border(bottom: BorderSide(width: 1, color: BG_SUB_COLOR, style: BorderStyle.solid))),
  119. child: Row(
  120. children: <Widget>[
  121. Container(
  122. margin: EdgeInsets.only(right: 12),
  123. width: 36,
  124. height: 36,
  125. child: info.userInfo != null
  126. ? CircleAvatar(
  127. backgroundImage: NetworkImage(info.userInfo.icon),
  128. )
  129. : Container(),
  130. ),
  131. Expanded(
  132. flex: 1,
  133. child: Text(
  134. info.userInfo != null ? info.userInfo.nickname : '',
  135. style: TextStyle(
  136. color: Colors.white,
  137. fontSize: 14,
  138. ),
  139. maxLines: 1,
  140. overflow: TextOverflow.ellipsis,
  141. ),
  142. ),
  143. widget.status == 4 && index < 3 && info.video != '' && info.video != null
  144. ? Container(
  145. width: 68,
  146. height: 24,
  147. margin: EdgeInsets.only(right: 30),
  148. child: OutlineButton(
  149. textColor: PRIMARY_COLOR,
  150. borderSide: BorderSide(color: PRIMARY_COLOR),
  151. padding: EdgeInsets.all(0),
  152. highlightColor: BG_SUB_COLOR.withOpacity(0.8),
  153. highlightedBorderColor: PRIMARY_COLOR,
  154. child: Text(
  155. '查看回放',
  156. style: TextStyle(fontSize: 12),
  157. ),
  158. onPressed: () =>
  159. {Navigator.push(context, CupertinoPageRoute(builder: (context) => VideoPlayerPage(videoUrl: info.video, fileType: 'netWork')))},
  160. ),
  161. )
  162. : Container(),
  163. img!=''
  164. ? Image.asset(
  165. img,
  166. width: 32,
  167. )
  168. : Text('')
  169. ],
  170. ),
  171. ),
  172. );
  173. }
  174. }