visit_page.dart 39 KB

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