confirm_order.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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:liftmanager/utils/oss_upload.dart';
  12. import 'dart:async';
  13. import 'package:liftmanager/utils/fast_notification.dart';
  14. import 'package:chewie/chewie.dart';
  15. import 'package:flutter/services.dart';
  16. import 'package:liftmanager/utils/utils.dart';
  17. import 'package:orientation/orientation.dart';
  18. import 'package:video_player/video_player.dart';
  19. import 'package:liftmanager/utils/theme_utils.dart';
  20. import 'package:liftmanager/widgets/selected_video_change.dart';
  21. import 'dart:io';
  22. class ConfirmOrder extends StatefulWidget {
  23. ConfirmOrder(this.id);
  24. final String id;
  25. @override
  26. State<StatefulWidget> createState() {
  27. return ConfirmOrderState();
  28. }
  29. }
  30. class ConfirmOrderState extends State<ConfirmOrder> {
  31. VideoPlayerController _controller;
  32. VideoPlayerController _controllerFile;
  33. // final FijkPlayer player = FijkPlayer();
  34. // List<String> imagesUrl = [];
  35. // List<String> videoUrl = [];
  36. String videoUrl;
  37. String str;
  38. String imagesUrl;
  39. double percent = 0.0;
  40. @override
  41. void initState() {
  42. super.initState();
  43. }
  44. ///选择图片
  45. void selectPicker() {
  46. showDialog(
  47. context: context,
  48. builder: (BuildContext context) {
  49. return SimpleDialog(
  50. title: Text("选择方式"),
  51. children: ["拍照", '从手机相册选择'].map((String value) {
  52. print("$value");
  53. return SimpleDialogOption(
  54. child: Text(
  55. "${value}",
  56. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  57. ),
  58. onPressed: () {
  59. _getImage(value == '拍照' ? 1 : 0);
  60. Navigator.of(context).pop();
  61. },
  62. );
  63. }).toList(),
  64. );
  65. },
  66. );
  67. }
  68. void _getImage(int key) async {
  69. print(key);
  70. print(333);
  71. try {
  72. await ImagePicker.pickVideo(
  73. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  74. )
  75. .then((File f) async{
  76. if (f != null) {
  77. _controllerFile = VideoPlayerController.file(f);
  78. _controllerFile.initialize().then((val){
  79. _controllerFile.setLooping(true);
  80. int seconds = _controllerFile.value.duration.inSeconds;
  81. print("视频时长:$seconds");
  82. int fileSize=f.lengthSync();//单位B
  83. print("视频大小:${fileSize}");
  84. print("视频大小:${f.path}");
  85. if (seconds <= 300) {
  86. _uploadImage(f.path);
  87. // upLoadFileOnce(_imageFile.path);
  88. // setState(() {});
  89. }else {
  90. toasts("视频时长不能大于5分钟!");
  91. }
  92. });}
  93. })
  94. ;
  95. } catch (e) {
  96. toasts("没有权限,无法打开相册!");
  97. }
  98. }
  99. void _uploadImage(filePath) async {
  100. showPercent(context, (){
  101. dismissLoading(context);
  102. toasts("上传失败");
  103. },(){
  104. if(videoUrl == null && str != null){
  105. setState(() {
  106. videoUrl = str;
  107. print("videoUrl:"+videoUrl);
  108. dismissLoading(context);
  109. toasts("上传成功");
  110. });
  111. }
  112. });
  113. String uploadName = OssUtil.instance.getImageUploadName(filePath);
  114. await NewApiService.uploadImage(context, uploadName, filePath).then((data) {
  115. if (data.statusCode == 200) {
  116. str = NewApiUrl.URL_UPLOAD_IMAGE_OSS + "/" + uploadName;
  117. print("str:"+str);
  118. print(videoUrl);
  119. if(str != null){
  120. Map obj = {
  121. "uploadName":uploadName,
  122. "success":true
  123. };
  124. FastNotification.push("percent",obj);
  125. }
  126. }else {
  127. Map obj = {
  128. "uploadName":uploadName,
  129. "success":false
  130. };
  131. FastNotification.push("percent",obj);
  132. }
  133. }).catchError((data) {
  134. Map obj = {
  135. "uploadName":uploadName,
  136. "success":false
  137. };
  138. FastNotification.push("percent",obj);
  139. });
  140. }
  141. upLoadFileOnce(path) {
  142. showLoading(context, "正在上传...");
  143. NewApiService().upload(path, onSuccess: (res) {
  144. dismissLoading(context);
  145. setState(() {
  146. videoUrl = res.pathUrl;
  147. imagesUrl = res.coverUrl;
  148. });
  149. }, onError: (code, msg) {
  150. dismissLoading(context);
  151. toasts(msg);
  152. });
  153. }
  154. submitApply() {
  155. if (videoUrl == null || videoUrl == '') {
  156. toasts("请上传视频");
  157. return;
  158. }
  159. showLoading(context);
  160. NewApiService().chargeMakeSureCase({
  161. "id": widget.id,
  162. "afterRepair": videoUrl,
  163. }, onSuccess: (res) {
  164. dismissLoading(context);
  165. toasts("确认完成");
  166. NavigatorUtils.push(context, "${WodeRouter.orderPageMaster}?checkType=0");
  167. setState(() {});
  168. }, onError: (code, msg) {
  169. dismissLoading(context);
  170. toasts(msg);
  171. });
  172. }
  173. // 文本编辑控制
  174. GlobalKey _formKey = new GlobalKey<FormState>();
  175. @override
  176. Widget build(BuildContext context) {
  177. double width = MediaQuery.of(context).size.width;
  178. return Scaffold(
  179. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  180. appBar: MyAppBar(
  181. centerTitle: "确认订单",
  182. ),
  183. body: Container(
  184. child: ListView(
  185. children: <Widget>[
  186. Form(
  187. key: _formKey, //设置globalKey,用于后面获取FormState
  188. // autovalidate: true, //开启自动校验
  189. child: Column(
  190. children: <Widget>[
  191. Container(
  192. width: width,
  193. padding: EdgeInsets.only(left:15,bottom:15),
  194. child: Text(
  195. "(建议时长3分钟,建议大小50M)",
  196. style: TextStyle(
  197. color: Colors.red,
  198. fontSize:
  199. ScreenUtil()
  200. .setSp(14),
  201. ),
  202. textAlign: TextAlign.left,
  203. ),
  204. ),
  205. // Container(
  206. // color: Colors.white,
  207. // child: GridView.builder(
  208. // shrinkWrap: true,
  209. // padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  210. // physics: NeverScrollableScrollPhysics(),
  211. // gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  212. // crossAxisCount: 3, childAspectRatio: 1.18),
  213. // itemCount: 1,
  214. // itemBuilder: (_, index) {
  215. // return Stack(
  216. // children: <Widget>[
  217. // Center(
  218. // child: SelectedImage(
  219. // image: imagesUrl,
  220. // index: index,
  221. // onTap: () {
  222. // selectPicker();
  223. // FocusScope.of(context).requestFocus(FocusNode());
  224. // },
  225. // ),
  226. // ),
  227. // videoUrl != null
  228. // ? Positioned(
  229. // top: 0,
  230. // right: 0,
  231. // child: GestureDetector(
  232. // onTap: () {
  233. // print(index);
  234. // videoUrl = null;
  235. // imagesUrl = null;
  236. // setState(() {});
  237. // },
  238. // child: Icon(
  239. // IconData(0xe62a, fontFamily: "myfont"),
  240. // size: 24.0,
  241. // color: Color(0xff999999),
  242. // ),
  243. // ),
  244. // )
  245. // : Container(
  246. // child: null,
  247. // )
  248. // ],
  249. // );
  250. // },
  251. // ),
  252. // ),
  253. Container(
  254. color: ThemeUtils.getDialogTextFieldColor(context),
  255. child: GridView.builder(
  256. shrinkWrap: true,
  257. padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  258. physics: NeverScrollableScrollPhysics(),
  259. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  260. crossAxisCount: 1, childAspectRatio: 1.18),
  261. itemCount: 1,
  262. itemBuilder: (_, index) {
  263. return Stack(
  264. children: <Widget>[
  265. Center(
  266. child: SelectedVideo(
  267. image: videoUrl,
  268. index: index,
  269. videoPlay:videoPlay(),
  270. onTap: () {
  271. if(videoUrl == null){
  272. selectPicker();
  273. }
  274. },
  275. ),
  276. ),
  277. videoUrl != null
  278. ? Positioned(
  279. top: 0,
  280. right: 0,
  281. child: GestureDetector(
  282. onTap: () {
  283. print(index);
  284. // imagesUrl = null;
  285. setState(() {
  286. videoUrl = null;
  287. str = null;
  288. _controller.pause();
  289. // player.reset();
  290. });
  291. },
  292. child: Icon(
  293. IconData(0xe62a, fontFamily: "myfont"),
  294. size: 24.0,
  295. color: Color(0xff999999),
  296. ),
  297. ),
  298. )
  299. : Container(
  300. child: null,
  301. )
  302. ],
  303. );
  304. },
  305. ),
  306. ),
  307. Container(
  308. height: ScreenUtil().setWidth(44),
  309. decoration: BoxDecoration(
  310. borderRadius:
  311. BorderRadius.circular(ScreenUtil().setWidth(22)),
  312. gradient: const LinearGradient(
  313. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
  314. ),
  315. margin: EdgeInsets.all(20.0),
  316. width: double.infinity,
  317. child: FlatButton(
  318. // padding: EdgeInsets.all(15.0),
  319. child: Text("提交"),
  320. // color: Theme
  321. // .of(context)
  322. // .primaryColor,
  323. textColor: Colors.white,
  324. onPressed: () {
  325. /*
  326. * 如果:context不对。可以使用GlobalKey,
  327. * 通过_formKey.currentState 获取FormState后,
  328. * 调用validate()方法校验用户名密码是否合法,校验
  329. * 通过后再提交数据。
  330. */
  331. if ((_formKey.currentState as FormState).validate()) {
  332. submitApply();
  333. }
  334. },
  335. ),
  336. ),
  337. ],
  338. ),
  339. ),
  340. ],
  341. ),
  342. ),
  343. );
  344. }
  345. Widget videoPlay() {
  346. _controller = VideoPlayerController.network(
  347. Utils.getImagePath(videoUrl)
  348. // imgFontUrl + detailObj.url
  349. );
  350. double width = MediaQuery.of(context).size.width;
  351. return
  352. // Container(
  353. // width: width,
  354. // height: width*0.6,
  355. // alignment: Alignment.center,
  356. // child: FijkView(
  357. // player: player,
  358. // color: Colors.black,
  359. // fit:FijkFit.fill,
  360. // // cover: NetworkImage(detailObj.cover),
  361. // // cover: new Image(image: detailObj.cover!=null&& detailObj.cover!=""?NetworkImage(detailObj.cover):AssetImage("assets/images/video_image.png"),).image,
  362. // //
  363. // ),
  364. // );
  365. Container(
  366. padding: EdgeInsets.only(
  367. left: ScreenUtil().setWidth(15),
  368. right: ScreenUtil().setWidth(15),
  369. top: ScreenUtil().setWidth(15)),
  370. child: ClipRRect(
  371. borderRadius: BorderRadius.circular(5),
  372. child:
  373. new Chewie(
  374. controller: ChewieController(
  375. videoPlayerController:
  376. // VideoPlayerController.network(
  377. // imgFontUrl + detailObj.url
  378. // ),
  379. _controller,
  380. aspectRatio: 3 / 2,
  381. allowFullScreen:false,
  382. autoPlay: false,
  383. looping: true,
  384. // startAt: Duration(seconds: 1,minutes: 1),
  385. showControls: true,
  386. deviceOrientationsAfterFullScreen:[DeviceOrientation.portraitUp],
  387. // 占位图
  388. // placeholder: Image.network(
  389. // imgFontUrl+detailObj.cover,
  390. // fit: BoxFit.contain,
  391. // ),
  392. // 是否在 UI 构建的时候就加载视频
  393. autoInitialize: true,
  394. // 拖动条样式颜色
  395. materialProgressColors:
  396. new ChewieProgressColors(
  397. playedColor: Colors.red,
  398. handleColor: Colors.blue,
  399. backgroundColor: Colors.grey,
  400. bufferedColor: Colors.lightGreen,
  401. ),
  402. ),
  403. ),
  404. )
  405. );
  406. }
  407. }