Appeal.dart 7.5 KB

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