jubao_page.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. import 'dart:io';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/foundation.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:image_picker/image_picker.dart';
  7. import 'package:keyboard_actions/keyboard_actions.dart';
  8. import 'package:liftmanager/internal/bbs/page/jubao_type.dart';
  9. import 'package:liftmanager/internal/team/page/input_text_page.dart';
  10. import 'package:liftmanager/net/api_service.dart';
  11. import 'package:liftmanager/res/resources.dart';
  12. import 'package:liftmanager/routers/fluro_navigator.dart';
  13. import 'package:liftmanager/utils/app_navigator.dart';
  14. import 'package:liftmanager/utils/theme_utils.dart';
  15. import 'package:liftmanager/utils/toast.dart';
  16. import 'package:liftmanager/widgets/app_bar.dart';
  17. import 'package:liftmanager/widgets/click_item.dart';
  18. import 'package:liftmanager/widgets/selected_image_change.dart';
  19. import 'package:liftmanager/widgets/my_button.dart';
  20. import 'package:liftmanager/widgets/text_field_item.dart';
  21. class JuBaoPage extends StatefulWidget {
  22. JuBaoPage({this.toUserId});
  23. String toUserId;
  24. @override
  25. State<StatefulWidget> createState() {
  26. return JuBaoPageState();
  27. }
  28. }
  29. class JuBaoPageState extends State<JuBaoPage> {
  30. File _imageFile;
  31. final FocusNode _nodeText1 = FocusNode();
  32. final FocusNode _nodeText2 = FocusNode();
  33. final FocusNode _nodeText3 = FocusNode();
  34. TextEditingController _teamNameController = TextEditingController();
  35. TextEditingController _nameController = TextEditingController();
  36. TextEditingController _phoneController = TextEditingController();
  37. TextEditingController _remarkController = TextEditingController();
  38. String _remarks = "";
  39. String _typeText = "";
  40. String _typeIndex = "";
  41. List<String> imagesUrl = [];
  42. void _getImage(int key) async {
  43. try {
  44. var _imageFile = await ImagePicker.pickImage(
  45. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  46. maxWidth: 800,
  47. imageQuality: 95);
  48. print(_imageFile);
  49. print(3333);
  50. if (_imageFile != null) {
  51. // images.add(_imageFile);
  52. upLoadFileOnce(_imageFile.path);
  53. // setState(() {});
  54. }
  55. } catch (e) {
  56. toasts("没有权限,无法打开相册!");
  57. }
  58. }
  59. //图片
  60. upLoadFileOnce(path) {
  61. showLoading(context, "正在上传...");
  62. NewApiService().upload(path, onSuccess: (res) {
  63. // imagesUrl.add(res.path);
  64. dismissLoading(context);
  65. setState(() {
  66. imagesUrl.add(res.pathUrl);
  67. // imageUrl = res.pathUrl;
  68. // videoUrl = null;
  69. });
  70. }, onError: (code, msg) {
  71. dismissLoading(context);
  72. toasts(msg);
  73. });
  74. }
  75. ///选择图片
  76. void selectPicker(type) {
  77. showDialog(
  78. context: context,
  79. builder: (BuildContext context) {
  80. return SimpleDialog(
  81. title: Text("选择方式"),
  82. children: ["拍照", '从手机相册选择'].map((String value) {
  83. print("$value");
  84. return SimpleDialogOption(
  85. child: Text(
  86. "${value}",
  87. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  88. ),
  89. onPressed: () {
  90. if (type == "image") {
  91. _getImage(value == '拍照' ? 1 : 0);
  92. } else if (type == "video") {
  93. // _getVideo(value == '拍照' ? 1 : 0);
  94. }
  95. Navigator.of(context).pop();
  96. },
  97. );
  98. }).toList());
  99. });
  100. }
  101. ///创建团队
  102. createTeamAction() {
  103. var remark = _remarkController.text.toString().trim();
  104. var name = _nameController.text.toString().trim();
  105. var phone = _phoneController.text.toString().trim();
  106. if (remark.isEmpty) {
  107. toasts("请描述原因");
  108. return;
  109. }
  110. if (name.isEmpty) {
  111. toasts("请填写联系人姓名");
  112. return;
  113. }
  114. if (phone.isEmpty) {
  115. toasts("请填写联系电话");
  116. return;
  117. }
  118. showLoading(context, "正在提交...");
  119. // {imgs,
  120. // name,
  121. // mobile,
  122. // comment,
  123. // type,
  124. // complainedUserId,
  125. String temp = '';
  126. for (var item in imagesUrl) {
  127. temp += item;
  128. temp += ',';
  129. }
  130. ApiService(context: context).jubao(
  131. imgs: temp,
  132. name: name,
  133. mobile: phone,
  134. comment: remark,
  135. type: _typeIndex,
  136. complainedUserId: widget.toUserId,
  137. onSuccess: (data) {
  138. showAlert(context, "提示", "举报成功!", "确定", () {
  139. dismissLoading(context);
  140. NavigatorUtils.goBack(context);
  141. NavigatorUtils.goBackWithParams(context, true);
  142. });
  143. },
  144. onError: (code, msg) {
  145. dismissLoading(context);
  146. toasts(msg);
  147. });
  148. }
  149. @override
  150. Widget build(BuildContext context) {
  151. return Scaffold(
  152. //resizeToAvoidBottomPadding: false,
  153. appBar: const MyAppBar(
  154. centerTitle: "举报",
  155. ),
  156. body: SafeArea(
  157. child: Column(
  158. children: <Widget>[
  159. Expanded(
  160. flex: 1,
  161. child: defaultTargetPlatform == TargetPlatform.iOS
  162. ? FormKeyboardActions(
  163. child: Container(
  164. color: ThemeUtils.getTabsBg(context),
  165. child: _buildBody(),
  166. ))
  167. : SingleChildScrollView(
  168. child: Container(
  169. color: ThemeUtils.getTabsBg(context),
  170. child: _buildBody(),
  171. )),
  172. )
  173. ],
  174. ),
  175. ),
  176. );
  177. }
  178. _buildBody() {
  179. return Padding(
  180. padding: const EdgeInsets.symmetric(vertical: 10.0),
  181. child: Stack(
  182. children: [
  183. Column(
  184. // crossAxisAlignment: CrossAxisAlignment.start,
  185. children: <Widget>[
  186. ClickItem(
  187. title: "举报理由",
  188. content: _typeText,
  189. onTap: () {
  190. Navigator.of(context).push(MaterialPageRoute(
  191. builder: (context) => JuBaoTypePage(
  192. backObj: (val, index) {
  193. _typeText = val;
  194. _typeIndex = index.toString();
  195. setState(() {});
  196. },
  197. )));
  198. },
  199. ),
  200. Container(
  201. // width: width,
  202. padding: EdgeInsets.only(left: 15, top: 10),
  203. alignment: Alignment.centerLeft,
  204. child: Text(
  205. "聊天证据",
  206. style: TextStyle(
  207. fontSize: ScreenUtil().setSp(14),
  208. ),
  209. textAlign: TextAlign.left,
  210. ),
  211. ),
  212. Container(
  213. color: ThemeUtils.getTabsBg(context),
  214. child: GridView.builder(
  215. shrinkWrap: true,
  216. padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  217. physics: NeverScrollableScrollPhysics(),
  218. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  219. crossAxisCount: 3, childAspectRatio: 1.18),
  220. itemCount:
  221. imagesUrl.length >= 9 ? 9 : imagesUrl.length + 1,
  222. itemBuilder: (_, index) {
  223. return Stack(
  224. children: <Widget>[
  225. Center(
  226. child: SelectedImage(
  227. image: index < imagesUrl.length
  228. ? imagesUrl[index]
  229. : null,
  230. index: index,
  231. onTap: () {
  232. if (index >= imagesUrl.length) {
  233. selectPicker("image");
  234. }
  235. FocusScope.of(context)
  236. .requestFocus(FocusNode());
  237. print(index);
  238. print(imagesUrl);
  239. }),
  240. ),
  241. index < imagesUrl.length
  242. ? Positioned(
  243. top: 0,
  244. right: 0,
  245. child: GestureDetector(
  246. onTap: () {
  247. print(index);
  248. imagesUrl.remove(imagesUrl[index]);
  249. setState(() {});
  250. },
  251. child: Icon(
  252. const IconData(0xe651,
  253. fontFamily: "Iconfont"),
  254. size: 24.0,
  255. color: Color(0xff999999),
  256. ),
  257. ))
  258. : Container(
  259. child: null,
  260. )
  261. ],
  262. );
  263. },
  264. )),
  265. Container(
  266. height: 120,
  267. padding: EdgeInsets.only(left: 15, right: 15, bottom: 10),
  268. child: TextFormField(
  269. // autofocus: true,
  270. maxLength: 100,
  271. cursorColor: Color(0xffcccccc),
  272. controller: _remarkController,
  273. maxLines: 5,
  274. decoration: InputDecoration(
  275. contentPadding: EdgeInsets.all(0),
  276. hintText: '详细描述',
  277. hintStyle: TextStyle(
  278. color: Color(0xffcccccc),
  279. fontSize: ScreenUtil().setSp(13),
  280. ),
  281. focusedBorder: InputBorder.none,
  282. border: InputBorder.none,
  283. // filled: true, // 背景色
  284. // fillColor: Colors.cyan.withAlpha(35),
  285. // icon: Icon(Icons.person)
  286. ),
  287. // 校验
  288. validator: (val) {
  289. return val.trim().length > 0 ? null : "不能为空";
  290. }),
  291. ),
  292. TextFieldItem(
  293. focusNode: _nodeText2,
  294. title: "联系人",
  295. controller: _nameController,
  296. hintText: "填写联系人姓名"),
  297. TextFieldItem(
  298. focusNode: _nodeText3,
  299. title: "联系方式",
  300. controller: _phoneController,
  301. hintText: "填写联系电话号码"),
  302. // Expanded(child: Container()),
  303. SizedBox(
  304. height: 100,
  305. ),
  306. ],
  307. ),
  308. Positioned(
  309. bottom: 5,
  310. left: 5,
  311. right: 5,
  312. child: MyButton(
  313. backColor: Colours.blue_app_main,
  314. onPressed: () {
  315. createTeamAction();
  316. },
  317. text: "提交",
  318. ),
  319. )
  320. ],
  321. ));
  322. }
  323. }