visit_page.dart 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. import 'dart:io';
  2. import 'package:chewie/chewie.dart';
  3. import 'package:date_format/date_format.dart';
  4. import 'package:flustars/flustars.dart' as flustars;
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter/services.dart';
  7. import 'package:flutter_cupertino_date_picker/flutter_cupertino_date_picker.dart';
  8. import 'package:flutter_picker/flutter_picker.dart';
  9. import 'package:flutter_screenutil/flutter_screenutil.dart';
  10. import 'package:image_picker/image_picker.dart';
  11. import 'package:liftmanager/common/common.dart';
  12. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  13. import 'package:liftmanager/internal/bbs/page/widgets.dart';
  14. import 'package:liftmanager/net/api_service.dart';
  15. import 'package:liftmanager/res/resources.dart';
  16. import 'package:liftmanager/routers/fluro_navigator.dart';
  17. import 'package:liftmanager/utils/fast_notification.dart';
  18. import 'package:liftmanager/utils/oss_upload.dart';
  19. import 'package:liftmanager/utils/theme_utils.dart';
  20. // 时间戳工具类
  21. import 'package:liftmanager/utils/time_format.dart';
  22. import 'package:liftmanager/utils/toast.dart';
  23. import 'package:liftmanager/utils/utils.dart';
  24. import 'package:liftmanager/widgets/app_bar.dart';
  25. import 'package:liftmanager/widgets/divider.dart';
  26. import 'package:liftmanager/widgets/selected_image_change.dart';
  27. import 'package:liftmanager/widgets/selected_video_change.dart';
  28. import 'package:orientation/orientation.dart';
  29. import 'package:permission_handler/permission_handler.dart';
  30. import 'package:shared_preferences/shared_preferences.dart';
  31. import 'package:video_player/video_player.dart';
  32. class VisitPage extends StatefulWidget {
  33. VisitPage(this.brandName, this.brandId);
  34. final String brandName;
  35. final String brandId;
  36. @override
  37. State<StatefulWidget> createState() {
  38. return VisitPageState();
  39. }
  40. }
  41. class VisitPageState extends State<VisitPage> {
  42. // NewsDetailItem item = NewsDetailItem();
  43. ScrollController _scrollController = new ScrollController();
  44. String extAddress;
  45. List<String> imagesUrl = [];
  46. // List<String> imagesUrlVideo = [];
  47. String videoUrl;
  48. String str;
  49. double percent = 0.0;
  50. String addressName = "";
  51. VideoPlayerController _controller;
  52. VideoPlayerController _controllerFile;
  53. ChewieController _chewieController;
  54. // String addressName = "湖北省武汉市洪山区武大科技园豪迈大厦,30.46139,114.414463";
  55. @override
  56. void initState() {
  57. super.initState();
  58. print(widget.brandName);
  59. print(widget.brandId);
  60. print(65656);
  61. FastNotification.addListener("set_address", (setAddress) {
  62. setState(() {
  63. addressName = setAddress;
  64. print(addressName);
  65. print(222222224);
  66. });
  67. });
  68. // getLocation();
  69. }
  70. Future<bool> requestPermission() async {
  71. final permissions = await PermissionHandler()
  72. .requestPermissions([PermissionGroup.location]);
  73. if (permissions[PermissionGroup.location] == PermissionStatus.granted) {
  74. return true;
  75. } else {
  76. toasts('需要定位权限!');
  77. return false;
  78. }
  79. }
  80. // getLocation() async {
  81. // if (await requestPermission()) {
  82. // Location location = await AmapLocation.fetchLocation();
  83. // String address = location.province + location.city + location.district + location.street + location.aoiName;
  84. // print(address);
  85. // setState(() {
  86. // addressName = address;
  87. // });
  88. // }
  89. // }
  90. @override
  91. void dispose() {
  92. _controller?.pause();
  93. _controller?.dispose();
  94. // _chewieController.videoPlayerController.dispose();
  95. // _chewieController.setLooping(false);
  96. _chewieController?.dispose();
  97. print('销毁了');
  98. // _controllerFile.dispose();
  99. super.dispose();
  100. }
  101. upLoadFileOnce(path) {
  102. showLoading(context, "正在上传...");
  103. NewApiService().upload(path, onSuccess: (res) {
  104. // imagesUrl.add(res.path);
  105. dismissLoading(context);
  106. setState(() {
  107. imagesUrl.add(res.pathUrl);
  108. });
  109. }, onError: (code, msg) {
  110. dismissLoading(context);
  111. toasts(msg);
  112. });
  113. }
  114. //视频
  115. upLoadFileOnceVideo(path) {
  116. showLoading(context, "正在上传...");
  117. NewApiService().upload(path, onSuccess: (res) {
  118. // imagesUrl.add(res.path);
  119. dismissLoading(context);
  120. setState(() {
  121. // videoUrl.add(res.pathUrl);
  122. // imagesUrlVideo.add(res.coverUrl);
  123. });
  124. }, onError: (code, msg) {
  125. dismissLoading(context);
  126. toasts(msg);
  127. });
  128. }
  129. ///选择图片
  130. void selectPicker(type) {
  131. showDialog(
  132. context: context,
  133. builder: (BuildContext context) {
  134. return SimpleDialog(
  135. title: Text("选择方式"),
  136. children: ["拍照", '从手机相册选择'].map((String value) {
  137. print("$value");
  138. return SimpleDialogOption(
  139. child: Text(
  140. "${value}",
  141. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  142. ),
  143. onPressed: () {
  144. if (type == "image") {
  145. _getImage(value == '拍照' ? 1 : 0);
  146. } else if (type == "video") {
  147. _getVideo(value == '拍照' ? 1 : 0);
  148. }
  149. Navigator.of(context).pop();
  150. },
  151. );
  152. }).toList());
  153. });
  154. }
  155. void _getImage(int key) async {
  156. try {
  157. var _imageFile = await ImagePicker.pickImage(
  158. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  159. maxWidth: 800,
  160. imageQuality: 95);
  161. print(_imageFile);
  162. print(3333);
  163. if (_imageFile != null) {
  164. // images.add(_imageFile);
  165. upLoadFileOnce(_imageFile.path);
  166. // setState(() {});
  167. }
  168. } catch (e) {
  169. toasts("没有权限,无法打开相册!");
  170. }
  171. }
  172. void _getVideo(int key) async {
  173. print(key);
  174. print(333);
  175. try {
  176. await ImagePicker.pickVideo(
  177. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  178. ).then((File f) async {
  179. if (f != null) {
  180. _controllerFile = VideoPlayerController.file(f);
  181. _controllerFile.initialize().then((val) {
  182. // _controllerFile.setLooping(true);
  183. int seconds = _controllerFile.value.duration.inSeconds;
  184. print("视频时长:$seconds");
  185. int fileSize = f.lengthSync(); //单位B
  186. print("视频大小:${fileSize}");
  187. print("视频大小:${f.path}");
  188. if (seconds > 300) {
  189. toasts("视频时长不能大于5分钟!");
  190. return;
  191. // upLoadFileOnce(_imageFile.path);
  192. // setState(() {});
  193. } else {}
  194. if (fileSize > (1024 * 1000 * 50)) {
  195. toasts("视频不能超过50M!");
  196. return;
  197. }
  198. _uploadImage(f.path);
  199. // _uploadImage(f.path);
  200. }).catchError((error) {
  201. print(error);
  202. print("error");
  203. toasts("上传失败,不支持此格式");
  204. });
  205. }
  206. });
  207. } catch (e) {
  208. toasts("没有权限,无法打开相册!");
  209. }
  210. }
  211. void _uploadImage(filePath) async {
  212. showPercent(context, () {
  213. dismissLoading(context);
  214. toasts("上传失败");
  215. }, () {
  216. if (videoUrl == null && str != null) {
  217. setState(() {
  218. videoUrl = str;
  219. settingVideo();
  220. // _controller =
  221. // VideoPlayerController.network(Utils.getImagePath(videoUrl));
  222. print("videoUrl:" + videoUrl);
  223. dismissLoading(context);
  224. toasts("上传成功");
  225. });
  226. }
  227. });
  228. String uploadName = OssUtil.instance.getImageUploadName(filePath);
  229. await NewApiService.uploadImage(context, uploadName, filePath).then((data) {
  230. if (data.statusCode == 200) {
  231. str = NewApiUrl.URL_UPLOAD_IMAGE_OSS + "/" + uploadName;
  232. print("str:" + str);
  233. print(videoUrl);
  234. if (str != null) {
  235. Map obj = {"uploadName": uploadName, "success": true};
  236. FastNotification.push("percent", obj);
  237. }
  238. } else {
  239. Map obj = {"uploadName": uploadName, "success": false};
  240. FastNotification.push("percent", obj);
  241. }
  242. }).catchError((data) {
  243. Map obj = {"uploadName": uploadName, "success": false};
  244. FastNotification.push("percent", obj);
  245. });
  246. }
  247. settingVideo() {
  248. _controller?.pause();
  249. _controller?.dispose();
  250. _chewieController?.dispose();
  251. _controller = VideoPlayerController.network(Utils.getImagePath(videoUrl));
  252. _chewieController = ChewieController(
  253. videoPlayerController: _controller,
  254. isLive: true,
  255. // aspectRatio: 1 / 2,
  256. allowFullScreen: false,
  257. autoPlay: false,
  258. looping: false, //循环播放
  259. // startAt: Duration(seconds: 1,minutes: 1),
  260. showControls: true,
  261. deviceOrientationsAfterFullScreen: [DeviceOrientation.portraitUp],
  262. // 是否在 UI 构建的时候就加载视频
  263. autoInitialize: true,
  264. // 拖动条样式颜色
  265. materialProgressColors: new ChewieProgressColors(
  266. playedColor: Colors.red,
  267. handleColor: Colors.blue,
  268. backgroundColor: Colors.grey,
  269. bufferedColor: Colors.lightGreen,
  270. ),
  271. );
  272. }
  273. FocusNode blankNode = FocusNode();
  274. // 文本编辑控制
  275. TextEditingController _textEditingController = new TextEditingController();
  276. // 焦点控制
  277. GlobalKey _formKey = new GlobalKey<FormState>();
  278. TextEditingController _questionController = new TextEditingController();
  279. TextEditingController _methodController = new TextEditingController();
  280. DateTime _nowDate = DateTime.now(); //当前日期
  281. DateTime _oldDate = DateTime.now(); //当前日期
  282. DateTime _nowDateTime = DateTime.parse(formatDate(DateTime.now(),
  283. [yyyy, "-", mm, "-", "dd", " ", HH, ":", nn, ":", ss])); //当前日期时间
  284. DateTime _yearTime; //当前日期时间
  285. String selectDateStr;
  286. @override
  287. Widget build(BuildContext context) {
  288. double width = MediaQuery.of(context).size.width;
  289. double height = MediaQuery.of(context).size.height;
  290. if (width > height) {
  291. // SystemChrome.setPreferredOrientations([
  292. // DeviceOrientation.portraitUp,
  293. // ]);
  294. OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
  295. }
  296. var _datetime =
  297. formatDate(_nowDate, [yyyy, "-", mm, "-", dd, " ", HH, ":", nn]);
  298. // _nowDate, [yyyy, "-", mm, "-", dd, " ", HH, ":", nn, ":", ss]);
  299. // var _datetime = formatDate(_nowDate,[yyyy, "-", mm, "-", dd, " ", HH]);
  300. _selectYear() {
  301. List yearList = [];
  302. for (var i = 1990; i <= DateTime.now().year + 1; i++) {
  303. yearList.add('$i年');
  304. }
  305. yearList.add('不详');
  306. new Picker(
  307. cancelText: "取消",
  308. confirmText: "确认",
  309. adapter: PickerDataAdapter<String>(pickerdata: yearList),
  310. changeToFirst: true,
  311. hideHeader: false,
  312. onConfirm: (Picker picker, List value) {
  313. selectDateStr = picker.getSelectedValues()[0];
  314. // widget.onConfirm(picker.getSelectedValues()[0], value[0]);
  315. setState(() {});
  316. },
  317. ).showModal(this.context);
  318. }
  319. //调起datetime_picker_bottom选择器
  320. _cupertinoDateTimePicker({isSelectYear = false}) {
  321. DatePicker.showDatePicker(
  322. context,
  323. minDateTime: DateTime.parse(isSelectYear ? '1990-01-01' : '2010-05-12'),
  324. //起始日期
  325. maxDateTime: DateTime.parse(isSelectYear ? '2020-10-10' : '2021-11-25'),
  326. //终止日期
  327. //initialDateTime: DateTime.parse(formatDate(_selectedDateTime, [yyyy, "-", mm, "-", "dd", " ", HH, ":", nn, ":", ss])),
  328. initialDateTime: _nowDateTime,
  329. //当前日期时间
  330. // dateFormat: "yyyy年M月d日 EEE,H时", //显示格式
  331. dateFormat: isSelectYear ? 'yyyy年' : "yyyy年M月d日 ,H时:m分",
  332. //显示格式
  333. // dateFormat: "yyyy年M月d日 ,H时:m分:s秒", //显示格式
  334. locale: DateTimePickerLocale.zh_cn,
  335. //语言
  336. pickerTheme: DateTimePickerTheme(
  337. showTitle: true,
  338. ),
  339. pickerMode: isSelectYear
  340. ? DateTimePickerMode.date
  341. : DateTimePickerMode.datetime,
  342. // show TimePicker
  343. onCancel: () {
  344. debugPrint('onCancel');
  345. },
  346. onChange: (dateTime, List<int> index) {
  347. setState(() {
  348. if (!isSelectYear) {
  349. _nowDate = dateTime;
  350. } else {
  351. _yearTime = dateTime;
  352. }
  353. });
  354. },
  355. onConfirm: (dateTime, List<int> index) {
  356. setState(() {
  357. if (!isSelectYear) {
  358. _nowDate = dateTime;
  359. } else {
  360. _yearTime = dateTime;
  361. }
  362. print(_nowDate);
  363. print(333333);
  364. });
  365. },
  366. );
  367. }
  368. _leftLine() {
  369. return Container(
  370. margin: EdgeInsets.only(top: ScreenUtil().setHeight(8)),
  371. width: ScreenUtil().setWidth(2),
  372. height: ScreenUtil().setHeight(13),
  373. color: Color(0xFF568AFF),
  374. );
  375. }
  376. return Scaffold(
  377. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  378. appBar: MyAppBar(
  379. centerTitle: "我要提问",
  380. ),
  381. body: GestureDetector(
  382. onTap: () {
  383. // 点击空白页面关闭键盘
  384. FocusScope.of(context).requestFocus(blankNode);
  385. },
  386. child: Stack(children: <Widget>[
  387. Container(
  388. padding: EdgeInsets.only(bottom: ScreenUtil().setWidth(80)),
  389. child: ListView(children: <Widget>[
  390. Form(
  391. key: _formKey, //设置globalKey,用于后面获取FormState
  392. // autovalidate: true, //开启自动校验
  393. child: Column(
  394. children: <Widget>[
  395. Container(
  396. padding: EdgeInsets.only(
  397. left: ScreenUtil().setWidth(10),
  398. right: ScreenUtil().setWidth(15),
  399. top: ScreenUtil().setWidth(10),
  400. bottom: ScreenUtil().setWidth(10)),
  401. // decoration: BoxDecoration(
  402. // // border: Border(
  403. // // bottom: BorderSide(width: 0.5, color: Colours.line),
  404. // // ),
  405. // ),
  406. child: Row(
  407. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  408. children: <Widget>[
  409. Text(
  410. "电梯品牌",
  411. style:
  412. TextStyle(fontSize: ScreenUtil().setSp(14)),
  413. textAlign: TextAlign.start,
  414. ),
  415. Text(
  416. widget.brandName,
  417. style: TextStyle(
  418. color: Color(0xff999999),
  419. // fontSize:ScreenUtil().setSp(14)
  420. ),
  421. textAlign: TextAlign.start,
  422. ),
  423. ]),
  424. ),
  425. CzDivider(
  426. margin:
  427. EdgeInsets.only(left: ScreenUtil().setWidth(10)),
  428. width: double.infinity),
  429. SelectCell(
  430. leftMargin: 4,
  431. title: '电梯出厂日期',
  432. subTitle: selectDateStr,
  433. onTap: () {
  434. _selectYear();
  435. }),
  436. CzDivider(
  437. margin:
  438. EdgeInsets.only(left: ScreenUtil().setWidth(10)),
  439. width: double.infinity),
  440. Container(
  441. padding: EdgeInsets.only(
  442. left: ScreenUtil().setWidth(10),
  443. right: ScreenUtil().setWidth(15),
  444. top: ScreenUtil().setWidth(10),
  445. bottom: ScreenUtil().setWidth(10)),
  446. child: Row(
  447. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  448. children: <Widget>[
  449. Text(
  450. "出诊时间",
  451. style:
  452. TextStyle(fontSize: ScreenUtil().setSp(14)),
  453. textAlign: TextAlign.start,
  454. ),
  455. _nowDate.millisecondsSinceEpoch ==
  456. _oldDate.millisecondsSinceEpoch
  457. ? InkWell(
  458. onTap: _cupertinoDateTimePicker,
  459. child: Text(
  460. "请选择时间",
  461. style: TextStyle(
  462. color: Color(0xff999999),
  463. // fontSize:ScreenUtil().setSp(14)
  464. ),
  465. textAlign: TextAlign.start,
  466. ))
  467. : Row(
  468. mainAxisAlignment: MainAxisAlignment.center,
  469. children: <Widget>[
  470. InkWell(
  471. onTap: _cupertinoDateTimePicker,
  472. child: Row(
  473. children: <Widget>[
  474. Text('$_datetime'),
  475. Icon(Icons.arrow_drop_down)
  476. ],
  477. ),
  478. )
  479. ],
  480. )
  481. ]),
  482. ),
  483. CzDivider(
  484. margin:
  485. EdgeInsets.only(left: ScreenUtil().setWidth(10)),
  486. width: double.infinity),
  487. SelectCell(
  488. leftMargin: 4,
  489. title: '出诊地点',
  490. subTitle: addressName != null && addressName != ""
  491. ? addressName.split(",")[0]
  492. : "请选择",
  493. onTap: () {
  494. if (_controller != null) {
  495. _controller.pause();
  496. }
  497. NavigatorUtils.push(
  498. context, "${BbsRouter.mapChoicePoint}?type=1");
  499. }),
  500. CzDivider(
  501. margin:
  502. EdgeInsets.only(left: ScreenUtil().setWidth(10)),
  503. width: double.infinity),
  504. Row(
  505. crossAxisAlignment: CrossAxisAlignment.start,
  506. mainAxisAlignment: MainAxisAlignment.start,
  507. children: <Widget>[
  508. _leftLine(),
  509. Container(
  510. padding: EdgeInsets.only(
  511. left: ScreenUtil().setWidth(10),
  512. top: ScreenUtil().setWidth(5),
  513. bottom: ScreenUtil().setWidth(5)),
  514. child: Text(
  515. "问题描述",
  516. style: TextStyle(
  517. // fontSize:ScreenUtil().setSp(14),miaos
  518. ),
  519. textAlign: TextAlign.left,
  520. ),
  521. ),
  522. ],
  523. ),
  524. Container(
  525. height: 100,
  526. padding: EdgeInsets.only(
  527. left: ScreenUtil().setWidth(15),
  528. right: ScreenUtil().setWidth(15),
  529. bottom: ScreenUtil().setWidth(20)),
  530. child: TextFormField(
  531. // autofocus: true,
  532. maxLength: 50,
  533. cursorColor: Color(0xffcccccc),
  534. controller: _questionController,
  535. maxLines: 5,
  536. decoration: InputDecoration(
  537. contentPadding: EdgeInsets.all(0),
  538. hintText: '请详细描述事故问题和现场情况',
  539. hintStyle: TextStyle(
  540. color: Color(0xffcccccc),
  541. ),
  542. focusedBorder: InputBorder.none,
  543. border: InputBorder.none,
  544. // filled: true, // 背景色
  545. // fillColor: Colors.cyan.withAlpha(35),
  546. // icon: Icon(Icons.person)
  547. ),
  548. // 校验
  549. validator: (val) {
  550. return val.trim().length > 0 ? null : "不能为空";
  551. }),
  552. ),
  553. CzDivider(
  554. margin:
  555. EdgeInsets.only(left: ScreenUtil().setWidth(10)),
  556. width: double.infinity),
  557. Row(
  558. crossAxisAlignment: CrossAxisAlignment.start,
  559. mainAxisAlignment: MainAxisAlignment.start,
  560. children: <Widget>[
  561. _leftLine(),
  562. Container(
  563. padding: EdgeInsets.only(
  564. left: ScreenUtil().setWidth(10),
  565. top: ScreenUtil().setWidth(5),
  566. bottom: ScreenUtil().setWidth(5)),
  567. child: Text(
  568. "已尝试方法",
  569. style: TextStyle(
  570. // fontSize:ScreenUtil().setSp(14),
  571. ),
  572. textAlign: TextAlign.left,
  573. ),
  574. ),
  575. ],
  576. ),
  577. Container(
  578. height: 100,
  579. padding: EdgeInsets.only(left: 15, right: 15, bottom: 20),
  580. child: TextFormField(
  581. // autofocus: true,
  582. maxLength: 50,
  583. cursorColor: Color(0xffcccccc),
  584. controller: _methodController,
  585. maxLines: 5,
  586. decoration: InputDecoration(
  587. contentPadding: EdgeInsets.all(0),
  588. hintText: '请详细描述已尝试方法以及结果',
  589. hintStyle: TextStyle(
  590. color: Color(0xffcccccc),
  591. // fontSize: ScreenUtil().setSp(14)
  592. ),
  593. focusedBorder: InputBorder.none,
  594. border: InputBorder.none,
  595. // filled: true, // 背景色
  596. // fillColor: Colors.cyan.withAlpha(35),
  597. // icon: Icon(Icons.person)
  598. ),
  599. // 校验
  600. validator: (val) {
  601. return val.trim().length > 0 ? null : "不能为空";
  602. }),
  603. ),
  604. CzDivider(
  605. margin:
  606. EdgeInsets.only(left: ScreenUtil().setWidth(10)),
  607. width: double.infinity),
  608. Row(
  609. children: [
  610. _leftLine(),
  611. Container(
  612. // width: width,
  613. padding: EdgeInsets.only(left: 10, top: 10),
  614. child: Text(
  615. "上传图片:",
  616. style: TextStyle(
  617. fontSize: ScreenUtil().setSp(14),
  618. ),
  619. textAlign: TextAlign.left,
  620. ),
  621. ),
  622. ],
  623. ),
  624. Container(
  625. color: ThemeUtils.getTabsBg(context),
  626. child: GridView.builder(
  627. shrinkWrap: true,
  628. padding:
  629. const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  630. physics: NeverScrollableScrollPhysics(),
  631. gridDelegate:
  632. SliverGridDelegateWithFixedCrossAxisCount(
  633. crossAxisCount: 3, childAspectRatio: 1.18),
  634. itemCount:
  635. imagesUrl.length >= 9 ? 9 : imagesUrl.length + 1,
  636. itemBuilder: (_, index) {
  637. return Stack(
  638. children: <Widget>[
  639. Center(
  640. child: SelectedImage(
  641. image: index < imagesUrl.length
  642. ? imagesUrl[index]
  643. : null,
  644. index: index,
  645. onTap: () {
  646. if (index >= imagesUrl.length) {
  647. selectPicker("image");
  648. }
  649. FocusScope.of(context)
  650. .requestFocus(FocusNode());
  651. print(index);
  652. print(imagesUrl);
  653. }),
  654. ),
  655. index < imagesUrl.length
  656. ? Positioned(
  657. top: 0,
  658. right: 0,
  659. child: GestureDetector(
  660. onTap: () {
  661. print(index);
  662. imagesUrl.remove(imagesUrl[index]);
  663. setState(() {});
  664. },
  665. child: Icon(
  666. const IconData(0xe651,
  667. fontFamily: "Iconfont"),
  668. size: 24.0,
  669. color: Color(0xff999999),
  670. ),
  671. ))
  672. : Container(
  673. child: null,
  674. )
  675. ],
  676. );
  677. },
  678. )),
  679. CzDivider(
  680. margin:
  681. EdgeInsets.only(left: ScreenUtil().setWidth(10)),
  682. width: double.infinity),
  683. Container(
  684. width: width,
  685. padding: EdgeInsets.only(left: 15, top: 15),
  686. child: Text(
  687. "上传视频:",
  688. style: TextStyle(
  689. fontSize: ScreenUtil().setSp(14),
  690. ),
  691. textAlign: TextAlign.left,
  692. ),
  693. ),
  694. Container(
  695. width: width,
  696. padding: EdgeInsets.only(left: 15, bottom: 15),
  697. child: Text(
  698. "(建议时长3分钟,建议大小50M)",
  699. style: TextStyle(
  700. color: Colors.red,
  701. fontSize: ScreenUtil().setSp(14),
  702. ),
  703. textAlign: TextAlign.left,
  704. ),
  705. ),
  706. SizedBox(
  707. height: 20,
  708. ),
  709. // Container(
  710. // color: ThemeUtils.getDialogTextFieldColor(context),
  711. // // padding: EdgeInsets.symmetric(vertical: 20),
  712. // height: 150,
  713. // width: 150,
  714. // child: Stack(
  715. // children: <Widget>[
  716. // Center(
  717. // child: SelectedVideo(
  718. // image: videoUrl,
  719. // videoPlay: videoPlay(),
  720. // onTap: () {
  721. // if (videoUrl == null) {
  722. // selectPicker("video");
  723. // }
  724. // },
  725. // ),
  726. // ),
  727. // videoUrl != null
  728. // ? Positioned(
  729. // top: 0,
  730. // right: 0,
  731. // child: GestureDetector(
  732. // onTap: () {
  733. // // imagesUrl = null;
  734. // setState(() {
  735. // videoUrl = null;
  736. // str = null;
  737. // _controller.pause();
  738. // // player.reset();
  739. // });
  740. // },
  741. // child: Icon(
  742. // const IconData(0xe651,
  743. // fontFamily: "Iconfont"),
  744. // size: 24.0,
  745. // color: Color(0xff999999),
  746. // ),
  747. // ),
  748. // )
  749. // : Container(
  750. // child: null,
  751. // )
  752. // ],
  753. // ),
  754. // ),
  755. Container(
  756. color: ThemeUtils.getDialogTextFieldColor(context),
  757. child: GridView.builder(
  758. shrinkWrap: true,
  759. padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  760. physics: NeverScrollableScrollPhysics(),
  761. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  762. crossAxisCount: 1, childAspectRatio: 1.18),
  763. itemCount: 1,
  764. itemBuilder: (_, index) {
  765. return Stack(
  766. children: <Widget>[
  767. Center(
  768. child: SelectedVideo(
  769. image: videoUrl,
  770. index: index,
  771. videoPlay: videoPlay(),
  772. onTap: () {
  773. if (videoUrl == null) {
  774. selectPicker("video");
  775. }
  776. },
  777. ),
  778. ),
  779. videoUrl != null
  780. ? Positioned(
  781. top: 0,
  782. right: 0,
  783. child: GestureDetector(
  784. onTap: () {
  785. print(index);
  786. // imagesUrl = null;
  787. setState(() {
  788. videoUrl = null;
  789. str = null;
  790. _controller.pause();
  791. // player.reset();
  792. });
  793. },
  794. child: Icon(
  795. const IconData(0xe651,
  796. fontFamily: "Iconfont"),
  797. size: 24.0,
  798. color: Color(0xff999999),
  799. ),
  800. ),
  801. )
  802. : Container(
  803. child: null,
  804. )
  805. ],
  806. );
  807. },
  808. ),
  809. ),
  810. ],
  811. ),
  812. ),
  813. ]),
  814. ),
  815. Positioned(
  816. bottom: 0,
  817. left: 0,
  818. child: Container(
  819. color: ThemeUtils.getDialogTextFieldColor(context),
  820. width: width,
  821. padding: EdgeInsets.only(
  822. top: ScreenUtil().setWidth(15),
  823. bottom: ScreenUtil().setWidth(15),
  824. left: ScreenUtil().setWidth(25),
  825. right: ScreenUtil().setWidth(25)),
  826. child: Container(
  827. height: ScreenUtil().setWidth(44),
  828. decoration: BoxDecoration(
  829. borderRadius: BorderRadius.circular(22.0),
  830. color: Colours.blue_app_main
  831. // gradient: const LinearGradient(
  832. // colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
  833. ),
  834. child: FlatButton(
  835. // padding: EdgeInsets.all(15.0),
  836. child: Text("提交"),
  837. textColor: Colors.white,
  838. // textColor: Colors.white,
  839. onPressed: () {
  840. // getExtAddress();
  841. print(_nowDate);
  842. print(_nowDate.toString().split(" ")[0] +
  843. " " +
  844. _nowDate.toString().split(" ")[1].substring(0, 5) +
  845. ":00");
  846. String time = _nowDate.toString().split(" ")[0] +
  847. " " +
  848. _nowDate.toString().split(" ")[1].substring(0, 5) +
  849. ":00";
  850. print(999994);
  851. if (DateUtils.instance
  852. .getTimeStap(formartData: _nowDate.toString()) <=
  853. DateUtils.instance
  854. .getTimeStap(formartData: _oldDate.toString())) {
  855. toasts("请选择正确的出诊时间");
  856. return;
  857. }
  858. if (addressName == null || addressName == "") {
  859. toasts("请选择出诊地点");
  860. return;
  861. }
  862. // if (imagesUrl.length < 1) {
  863. // toasts("请上传图片");
  864. // return;
  865. // }
  866. String imgs = "";
  867. if (imagesUrl.length > 0) {
  868. imgs = imagesUrl.join(",");
  869. }
  870. // String videoImgs = "";
  871. // if(videoUrl.length > 0){
  872. // videoImgs = videoUrl.join(",");
  873. // }
  874. if ((_formKey.currentState as FormState).validate()) {
  875. dynamic obj = {
  876. "dataTable": "2",
  877. "brandId": widget.brandId,
  878. "expression": _questionController.text,
  879. "usedMethods": _methodController.text,
  880. "imgs": imgs,
  881. "videoUrl": videoUrl,
  882. "createUserId": int.parse(
  883. flustars.SpUtil.getString(Constant.userId)),
  884. "chargerId": 1,
  885. 'productionDate': selectDateStr,
  886. "arrivedTime": DateUtils.instance
  887. .getTimeStap(formartData: time.toString()),
  888. // _nowDate.toString().split(" ")[0] +"T" +_nowDate.toString().split(" ")[1],
  889. // "arrivedTime":_nowDate.toString().split(" ")[0]+"T"+_nowDate.toString().split(" ")[1].substring(0, 2)+":00:00.000",
  890. "address": addressName.split(",")[0],
  891. "lat": addressName.split(",")[1],
  892. "lng": addressName.split(",")[2],
  893. };
  894. showLoading(context, "正在提交...");
  895. NewApiService().createCase(obj, onSuccess: (res) {
  896. dismissLoading(context);
  897. toasts("提交成功");
  898. FocusScope.of(context).requestFocus(FocusNode());
  899. print(res);
  900. print(999999);
  901. setDataId(res);
  902. setType("2");
  903. if (_controller != null) {
  904. _controller.pause();
  905. }
  906. NavigatorUtils.push(context,
  907. "${BbsRouter.expertList}?id=${widget.brandId}");
  908. }, onError: (code, msg) {
  909. dismissLoading(context);
  910. toasts(msg);
  911. });
  912. }
  913. },
  914. ),
  915. ),
  916. ))
  917. ]),
  918. ),
  919. );
  920. }
  921. void setDataId(int id) async {
  922. SharedPreferences prefs = await SharedPreferences.getInstance();
  923. prefs.setInt("dataId", id);
  924. }
  925. void setType(String type) async {
  926. SharedPreferences prefs = await SharedPreferences.getInstance();
  927. prefs.setString("questionType", type);
  928. }
  929. // void getExtAddress ()async{
  930. // SharedPreferences prefs = await SharedPreferences.getInstance();
  931. // extAddress = prefs.getString("extAddress");
  932. // }
  933. Widget videoPlay() {
  934. if (_controller == null) return Container();
  935. return Container(
  936. child: ClipRRect(
  937. borderRadius: BorderRadius.circular(5),
  938. child: new Chewie(controller: _chewieController),
  939. ));
  940. }
  941. }