visit_page.dart 41 KB

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