Appeal.dart 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import 'dart:io';
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:dio/dio.dart';
  4. import 'package:file_picker/file_picker.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter/widgets.dart';
  7. import 'package:flutter_redux/flutter_redux.dart';
  8. import 'package:image_picker/image_picker.dart';
  9. import 'package:wanna_battle/model/PlayerInfo.dart';
  10. import 'package:wanna_battle/net/HttpManager.dart';
  11. import 'package:wanna_battle/net/Result.dart';
  12. import 'package:wanna_battle/redux/AppState.dart';
  13. import 'package:wanna_battle/styles/colors.dart';
  14. import 'package:wanna_battle/styles/totast.dart';
  15. class Appeal extends StatefulWidget {
  16. final PlayerInfo playerInfo;
  17. const Appeal(this.playerInfo, {Key key}) : super(key: key);
  18. @override
  19. State<StatefulWidget> createState() {
  20. return AppealState();
  21. }
  22. }
  23. class AppealState extends State<Appeal> {
  24. String img1;
  25. String img2;
  26. @override
  27. Widget build(BuildContext context) {
  28. return WillPopScope(
  29. onWillPop: () {
  30. return Future.value(true);
  31. },
  32. child: Scaffold(
  33. backgroundColor: Color(0xFF3A3D5C),
  34. appBar: AppBar(
  35. title: Text('上传比赛结果'),
  36. centerTitle: true,
  37. ),
  38. body: Column(
  39. children: <Widget>[
  40. Expanded(
  41. child: ListView(
  42. padding: EdgeInsets.only(left: 15, top: 18, right: 15, bottom: 18),
  43. children: <Widget>[
  44. Container(
  45. padding: EdgeInsets.all(3),
  46. child: Text(
  47. '很遗憾,因为部分手机系统性能问题导致比赛结果上传失败,请你按照下图所示方式上传历史战绩以及本次游戏比赛详情战绩,工作人员审核后会根据实际情况进行名次的排序以及奖励的发放',
  48. style: TextStyle(color: Colors.white, fontSize: 14),
  49. ),
  50. ),
  51. Container(
  52. margin: EdgeInsets.only(top: 20),
  53. child: Row(
  54. children: <Widget>[
  55. Expanded(
  56. child: Container(
  57. padding: EdgeInsets.only(right: 7),
  58. child: imgUpload('点击上传历史战绩截图', img1, (img) {
  59. setState(() {
  60. img1 = img;
  61. });
  62. }),
  63. ),
  64. ),
  65. Expanded(
  66. child: Container(
  67. padding: EdgeInsets.only(left: 7),
  68. child: imgUpload('点击上传战绩详情截图', img2, (img) {
  69. setState(() {
  70. img2 = img;
  71. });
  72. }),
  73. ),
  74. ),
  75. ],
  76. ),
  77. ),
  78. Container(
  79. margin: EdgeInsets.only(top: 30),
  80. child: Text(
  81. '历史战绩-图片示例',
  82. textAlign: TextAlign.center,
  83. style: TextStyle(color: Colors.white, fontSize: 14),
  84. ),
  85. ),
  86. Container(
  87. margin: EdgeInsets.only(top: 10),
  88. child: Image.asset(
  89. 'images/shili_img_01.png',
  90. fit: BoxFit.cover,
  91. ),
  92. ),
  93. Container(
  94. margin: EdgeInsets.only(top: 20),
  95. child: Text(
  96. '战绩详情-图片示例',
  97. textAlign: TextAlign.center,
  98. style: TextStyle(color: Colors.white, fontSize: 14),
  99. ),
  100. ),
  101. Container(
  102. margin: EdgeInsets.only(top: 10),
  103. child: Image.asset(
  104. 'images/shili_img_02.png',
  105. fit: BoxFit.cover,
  106. ),
  107. ),
  108. ],
  109. ),
  110. ),
  111. SafeArea(
  112. child: Container(
  113. height: 68,
  114. width: double.infinity,
  115. padding: EdgeInsets.fromLTRB(15, 10, 15, 10),
  116. child: FlatButton(
  117. color: PRIMARY_COLOR,
  118. child: Text(
  119. '提交',
  120. style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
  121. ),
  122. onPressed: () async {
  123. if (img1 == null || img1.isEmpty) {
  124. Toast.show(context, '请上传历史战绩截图', 1500, 'info');
  125. } else if (img2 == null || img2.isEmpty) {
  126. Toast.show(context, '请上传战绩详情截图', 1500, 'info');
  127. } else {
  128. Toast.show(context, '加载中', -1, 'loading');
  129. final res = await HttpManager.post('appealInfo/save', data: {
  130. 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
  131. 'playerInfoId': widget.playerInfo.id,
  132. 'houseId': widget.playerInfo.houseId,
  133. 'pic': img1 + ',' + img2,
  134. });
  135. Toast.hide();
  136. if (res.success) {
  137. Navigator.of(context).pop(true);
  138. } else {
  139. Toast.show(context, '提交失败,请稍后再试', 1500, 'info');
  140. }
  141. }
  142. },
  143. ),
  144. ),
  145. )
  146. ],
  147. ),
  148. ),
  149. );
  150. }
  151. Widget imgUpload(String txt, String img, Function(String img) onUploadSuccess) {
  152. return GestureDetector(
  153. child: img != null && img.isNotEmpty
  154. ? Container(
  155. height: 111,
  156. decoration: BoxDecoration(border: Border.all(width: 1, color: Color(0xFF92434A)), color: Color(0xFF293354)),
  157. child: CachedNetworkImage(
  158. imageUrl: img,
  159. height: 111,
  160. fit: BoxFit.contain,
  161. ),
  162. )
  163. : Container(
  164. height: 111,
  165. decoration: BoxDecoration(border: Border.all(width: 1, color: Color(0xFF92434A)), color: Color(0xFF293354)),
  166. child: Column(
  167. mainAxisSize: MainAxisSize.max,
  168. mainAxisAlignment: MainAxisAlignment.center,
  169. children: <Widget>[
  170. Image.asset('images/icon_shangchuan.png', width: 34),
  171. Container(
  172. margin: EdgeInsets.only(top: 10),
  173. child: Text(
  174. txt,
  175. style: TextStyle(color: PRIMARY_COLOR, fontSize: 13),
  176. ),
  177. )
  178. ],
  179. ),
  180. ),
  181. onTap: () async {
  182. File file = await ImagePicker.pickImage(source: ImageSource.gallery, maxWidth: 1000);
  183. if (file == null) {
  184. return;
  185. }
  186. Toast.show(context, '加载中', -1, 'loading');
  187. Result res = await HttpManager.post('assets/uploadFile', data: {
  188. 'file': UploadFileInfo(file, file.path),
  189. });
  190. Toast.hide();
  191. print(res.toJson());
  192. if (res.success) {
  193. onUploadSuccess(res.data[0]);
  194. }
  195. },
  196. );
  197. }
  198. }