confirm_order.dart 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/net/api_service.dart';
  3. import 'package:liftmanager/utils/toast.dart';
  4. import 'package:liftmanager/widgets/app_bar.dart';
  5. import 'package:liftmanager/routers/fluro_navigator.dart';
  6. import 'package:liftmanager/widgets/selected_image_change.dart';
  7. import 'package:image_picker/image_picker.dart';
  8. import 'package:flutter_screenutil/flutter_screenutil.dart';
  9. import 'package:liftmanager/internal/wode/wode_router.dart';
  10. import 'package:permission_handler/permission_handler.dart';
  11. // import 'package:amap_all_fluttify/amap_all_fluttify.dart';
  12. class ConfirmOrder extends StatefulWidget {
  13. ConfirmOrder(this.id);
  14. final String id;
  15. @override
  16. State<StatefulWidget> createState() {
  17. return ConfirmOrderState();
  18. }
  19. }
  20. class ConfirmOrderState extends State<ConfirmOrder> {
  21. String videoUrl;
  22. String imagesUrl;
  23. @override
  24. void initState() {
  25. super.initState();
  26. }
  27. ///选择图片
  28. void selectPicker() {
  29. showDialog(
  30. context: context,
  31. builder: (BuildContext context) {
  32. return SimpleDialog(
  33. title: Text("选择方式"),
  34. children: ["拍照", '从手机相册选择'].map((String value) {
  35. print("$value");
  36. return SimpleDialogOption(
  37. child: Text(
  38. "${value}",
  39. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  40. ),
  41. onPressed: () {
  42. _getImage(value == '拍照' ? 1 : 0);
  43. Navigator.of(context).pop();
  44. },
  45. );
  46. }).toList(),
  47. );
  48. },
  49. );
  50. }
  51. void _getImage(int key) async {
  52. try {
  53. var _imageFile = await ImagePicker.pickVideo(
  54. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  55. );
  56. if (_imageFile != null) {
  57. upLoadFileOnce(_imageFile.path);
  58. }
  59. } catch (e) {
  60. toasts("没有权限,无法打开相册!");
  61. }
  62. }
  63. upLoadFileOnce(path) {
  64. showLoading(context, "正在上传...");
  65. NewApiService().upload(path, onSuccess: (res) {
  66. dismissLoading(context);
  67. setState(() {
  68. videoUrl = res.pathUrl;
  69. imagesUrl = res.coverUrl;
  70. });
  71. }, onError: (code, msg) {
  72. dismissLoading(context);
  73. toasts(msg);
  74. });
  75. }
  76. submitApply() {
  77. if (videoUrl == null || videoUrl == '') {
  78. toasts("请上传视频");
  79. return;
  80. }
  81. showLoading(context);
  82. NewApiService().chargeMakeSureCase({
  83. "id": widget.id,
  84. "afterRepair": videoUrl,
  85. }, onSuccess: (res) {
  86. dismissLoading(context);
  87. toasts("确认完成");
  88. NavigatorUtils.push(context, "${WodeRouter.orderPageMaster}?checkType=0");
  89. setState(() {});
  90. }, onError: (code, msg) {
  91. dismissLoading(context);
  92. toasts(msg);
  93. });
  94. }
  95. // 文本编辑控制
  96. GlobalKey _formKey = new GlobalKey<FormState>();
  97. @override
  98. Widget build(BuildContext context) {
  99. double width = MediaQuery.of(context).size.width;
  100. return Scaffold(
  101. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  102. appBar: MyAppBar(
  103. centerTitle: "确认订单",
  104. ),
  105. body: Container(
  106. child: ListView(
  107. children: <Widget>[
  108. Form(
  109. key: _formKey, //设置globalKey,用于后面获取FormState
  110. // autovalidate: true, //开启自动校验
  111. child: Column(
  112. children: <Widget>[
  113. Container(
  114. width: width,
  115. padding: EdgeInsets.only(left:15),
  116. child: Text(
  117. "(建议时长3分钟,建议大小50M)",
  118. style: TextStyle(
  119. color: Colors.red,
  120. fontSize:
  121. ScreenUtil()
  122. .setSp(14),
  123. ),
  124. textAlign: TextAlign.left,
  125. ),
  126. ),
  127. Container(
  128. color: Colors.white,
  129. child: GridView.builder(
  130. shrinkWrap: true,
  131. padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  132. physics: NeverScrollableScrollPhysics(),
  133. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  134. crossAxisCount: 3, childAspectRatio: 1.18),
  135. itemCount: 1,
  136. itemBuilder: (_, index) {
  137. return Stack(
  138. children: <Widget>[
  139. Center(
  140. child: SelectedImage(
  141. image: imagesUrl,
  142. index: index,
  143. onTap: () {
  144. selectPicker();
  145. FocusScope.of(context).requestFocus(FocusNode());
  146. },
  147. ),
  148. ),
  149. videoUrl != null
  150. ? Positioned(
  151. top: 0,
  152. right: 0,
  153. child: GestureDetector(
  154. onTap: () {
  155. print(index);
  156. videoUrl = null;
  157. imagesUrl = null;
  158. setState(() {});
  159. },
  160. child: Icon(
  161. IconData(0xe62a, fontFamily: "myfont"),
  162. size: 24.0,
  163. color: Color(0xff999999),
  164. ),
  165. ),
  166. )
  167. : Container(
  168. child: null,
  169. )
  170. ],
  171. );
  172. },
  173. ),
  174. ),
  175. Container(
  176. height: ScreenUtil().setWidth(44),
  177. decoration: BoxDecoration(
  178. borderRadius:
  179. BorderRadius.circular(ScreenUtil().setWidth(22)),
  180. gradient: const LinearGradient(
  181. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
  182. ),
  183. margin: EdgeInsets.all(20.0),
  184. width: double.infinity,
  185. child: FlatButton(
  186. // padding: EdgeInsets.all(15.0),
  187. child: Text("提交"),
  188. // color: Theme
  189. // .of(context)
  190. // .primaryColor,
  191. textColor: Colors.white,
  192. onPressed: () {
  193. /*
  194. * 如果:context不对。可以使用GlobalKey,
  195. * 通过_formKey.currentState 获取FormState后,
  196. * 调用validate()方法校验用户名密码是否合法,校验
  197. * 通过后再提交数据。
  198. */
  199. if ((_formKey.currentState as FormState).validate()) {
  200. submitApply();
  201. }
  202. },
  203. ),
  204. ),
  205. ],
  206. ),
  207. ),
  208. ],
  209. ),
  210. ),
  211. );
  212. }
  213. }