visit_page.dart 41 KB

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