visit_page.dart 41 KB

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