visit_page.dart 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  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. if(_controller!=null){
  410. _controller.pause();
  411. }
  412. NavigatorUtils.push(
  413. context, "${BbsRouter.mapChoicePoint}?type=1");
  414. },
  415. child: Container(
  416. padding: EdgeInsets.only(
  417. left: ScreenUtil().setWidth(15),
  418. right: ScreenUtil().setWidth(15),
  419. top: ScreenUtil().setWidth(10),
  420. bottom: ScreenUtil().setWidth(10)),
  421. decoration: BoxDecoration(
  422. border: Border(
  423. bottom:
  424. BorderSide(width: 0.5, color: Colours.line),
  425. ),
  426. ),
  427. child: Row(
  428. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  429. children: <Widget>[
  430. Text(
  431. "出诊地点 ",
  432. style: TextStyle(
  433. // fontSize:ScreenUtil().setSp(14)
  434. ),
  435. textAlign: TextAlign.start,
  436. ),
  437. Expanded(
  438. child: Text(
  439. addressName != null && addressName != ""
  440. ? addressName.split(",")[0]
  441. : "请选择",
  442. style: TextStyle(
  443. color: Color(0xff999999),
  444. // fontSize:ScreenUtil().setSp(14)
  445. ),
  446. textAlign: TextAlign.end,
  447. maxLines: 1,
  448. overflow: TextOverflow.ellipsis,
  449. ),
  450. )
  451. ]),
  452. ),
  453. ),
  454. Row(
  455. crossAxisAlignment: CrossAxisAlignment.start,
  456. mainAxisAlignment: MainAxisAlignment.start,
  457. children: <Widget>[
  458. Container(
  459. padding: EdgeInsets.only(
  460. left: ScreenUtil().setWidth(15),
  461. top: ScreenUtil().setWidth(5),
  462. bottom: ScreenUtil().setWidth(5)),
  463. child: Text(
  464. "问题描述",
  465. style: TextStyle(
  466. // fontSize:ScreenUtil().setSp(14),miaos
  467. ),
  468. textAlign: TextAlign.left,
  469. ),
  470. ),
  471. ],
  472. ),
  473. Container(
  474. height: 100,
  475. padding: EdgeInsets.only(
  476. left: ScreenUtil().setWidth(15),
  477. right: ScreenUtil().setWidth(15),
  478. bottom: ScreenUtil().setWidth(20)),
  479. child: TextFormField(
  480. // autofocus: true,
  481. maxLength: 50,
  482. cursorColor: Color(0xffcccccc),
  483. controller: _questionController,
  484. maxLines: 5,
  485. decoration: InputDecoration(
  486. contentPadding: EdgeInsets.all(0),
  487. hintText: '请详细描述事故问题和现场情况',
  488. hintStyle: TextStyle(
  489. color: Color(0xffcccccc),
  490. // fontSize: ScreenUtil().setSp(14)
  491. ),
  492. focusedBorder: InputBorder.none,
  493. border: InputBorder.none,
  494. // filled: true, // 背景色
  495. // fillColor: Colors.cyan.withAlpha(35),
  496. // icon: Icon(Icons.person)
  497. ),
  498. // 校验
  499. validator: (val) {
  500. return val.trim().length > 0 ? null : "不能为空";
  501. }),
  502. ),
  503. SizedBox(
  504. height: 6,
  505. child: Container(color: ThemeUtils.getDialogTextFieldColor(context)),
  506. ),
  507. Row(
  508. crossAxisAlignment: CrossAxisAlignment.start,
  509. mainAxisAlignment: MainAxisAlignment.start,
  510. children: <Widget>[
  511. Container(
  512. padding: EdgeInsets.only(
  513. left: ScreenUtil().setWidth(15),
  514. top: ScreenUtil().setWidth(5),
  515. bottom: ScreenUtil().setWidth(5)),
  516. child: Text(
  517. "已尝试方法",
  518. style: TextStyle(
  519. // fontSize:ScreenUtil().setSp(14),
  520. ),
  521. textAlign: TextAlign.left,
  522. ),
  523. ),
  524. ],
  525. ),
  526. Container(
  527. height: 100,
  528. padding:
  529. EdgeInsets.only(left: 15, right: 15, bottom: 20),
  530. child: TextFormField(
  531. // autofocus: true,
  532. maxLength: 50,
  533. cursorColor: Color(0xffcccccc),
  534. controller: _methodController,
  535. maxLines: 5,
  536. decoration: InputDecoration(
  537. contentPadding: EdgeInsets.all(0),
  538. hintText: '请详细描述已尝试方法以及结果',
  539. hintStyle: TextStyle(
  540. color: Color(0xffcccccc),
  541. // fontSize: ScreenUtil().setSp(14)
  542. ),
  543. focusedBorder: InputBorder.none,
  544. border: InputBorder.none,
  545. // filled: true, // 背景色
  546. // fillColor: Colors.cyan.withAlpha(35),
  547. // icon: Icon(Icons.person)
  548. ),
  549. // 校验
  550. validator: (val) {
  551. return val.trim().length > 0 ? null : "不能为空";
  552. }),
  553. ),
  554. SizedBox(
  555. height: 6,
  556. child: Container(color: ThemeUtils.getDialogTextFieldColor(context)),
  557. ),
  558. Container(
  559. width: width,
  560. padding: EdgeInsets.only(left:15,top:15),
  561. child: Text(
  562. "上传图片:",
  563. style: TextStyle(
  564. fontSize:
  565. ScreenUtil()
  566. .setSp(14),
  567. ),
  568. textAlign: TextAlign.left,
  569. ),
  570. ),
  571. Container(
  572. color: ThemeUtils.getTabsBg(context),
  573. child: GridView.builder(
  574. shrinkWrap: true,
  575. padding:
  576. const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  577. physics: NeverScrollableScrollPhysics(),
  578. gridDelegate:
  579. SliverGridDelegateWithFixedCrossAxisCount(
  580. crossAxisCount: 3, childAspectRatio: 1.18),
  581. itemCount: imagesUrl.length >= 9
  582. ? 9
  583. : imagesUrl.length + 1,
  584. itemBuilder: (_, index) {
  585. return Stack(
  586. children: <Widget>[
  587. Center(
  588. child: SelectedImage(
  589. image: index < imagesUrl.length
  590. ? imagesUrl[index]
  591. : null,
  592. index: index,
  593. onTap: () {
  594. if (index >= imagesUrl.length) {
  595. selectPicker("image");
  596. }
  597. FocusScope.of(context)
  598. .requestFocus(FocusNode());
  599. print(index);
  600. print(imagesUrl);
  601. }),
  602. ),
  603. index < imagesUrl.length
  604. ? Positioned(
  605. top: 0,
  606. right: 0,
  607. child: GestureDetector(
  608. onTap: () {
  609. print(index);
  610. imagesUrl
  611. .remove(imagesUrl[index]);
  612. setState(() {});
  613. },
  614. child: Icon(
  615. IconData(0xe62a,
  616. fontFamily: "myfont"),
  617. size: 24.0,
  618. color: Color(0xff999999),
  619. ),
  620. ))
  621. : Container(
  622. child: null,
  623. )
  624. ],
  625. );
  626. },
  627. )),
  628. SizedBox(
  629. height:6,
  630. child: Container(
  631. color:ThemeUtils.getDialogTextFieldColor(context)
  632. ),
  633. ),
  634. Container(
  635. width: width,
  636. padding: EdgeInsets.only(left:15,top:15),
  637. child: Text(
  638. "上传视频:",
  639. style: TextStyle(
  640. fontSize:
  641. ScreenUtil()
  642. .setSp(14),
  643. ),
  644. textAlign: TextAlign.left,
  645. ),
  646. ),
  647. Container(
  648. width: width,
  649. padding: EdgeInsets.only(left:15,bottom:15),
  650. child: Text(
  651. "(建议时长3分钟,建议大小50M)",
  652. style: TextStyle(
  653. color: Colors.red,
  654. fontSize:
  655. ScreenUtil()
  656. .setSp(14),
  657. ),
  658. textAlign: TextAlign.left,
  659. ),
  660. ),
  661. // Container(
  662. // color: ThemeUtils.getTabsBg(context),
  663. // child: GridView.builder(
  664. // shrinkWrap: true,
  665. // padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  666. // physics: NeverScrollableScrollPhysics(),
  667. // gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  668. // crossAxisCount: 3, childAspectRatio: 1.18),
  669. // itemCount: videoUrl.length >= 1 ? 1 : videoUrl.length + 1,
  670. // itemBuilder: (_, index) {
  671. // return Stack(
  672. // children: <Widget>[
  673. // Center(
  674. // child: SelectedImage(
  675. // image: index < videoUrl.length ? imagesUrlVideo[index] : null,
  676. // index:index,
  677. // onTap: () {
  678. // if(index >= videoUrl.length){
  679. // selectPicker("video");
  680. // }
  681. // FocusScope.of(context).requestFocus(FocusNode());
  682. // print(index);
  683. // print(videoUrl);
  684. // }),
  685. // ),
  686. // index < videoUrl.length?Positioned(
  687. // top:0,
  688. // right:0,
  689. // child:GestureDetector(
  690. // onTap: (){
  691. // print(index);
  692. // videoUrl.remove(videoUrl[index]);
  693. // imagesUrlVideo.remove(imagesUrlVideo[index]);
  694. // setState(() {
  695. // });
  696. // },
  697. // child:Icon(
  698. // IconData(
  699. // 0xe62a,
  700. // fontFamily:"myfont"
  701. // ),
  702. // size: 24.0,
  703. // color:Color(0xff999999),
  704. // ),
  705. // )
  706. // ):Container(child: null,)
  707. // ],
  708. // );
  709. // },
  710. // )
  711. // ),
  712. Container(
  713. color: ThemeUtils.getDialogTextFieldColor(context),
  714. child: GridView.builder(
  715. shrinkWrap: true,
  716. padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  717. physics: NeverScrollableScrollPhysics(),
  718. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  719. crossAxisCount: 1, childAspectRatio: 1.18),
  720. itemCount: 1,
  721. itemBuilder: (_, index) {
  722. return Stack(
  723. children: <Widget>[
  724. Center(
  725. child: SelectedVideo(
  726. image: videoUrl,
  727. index: index,
  728. videoPlay:videoPlay(),
  729. onTap: () {
  730. if(videoUrl == null){
  731. selectPicker("video");
  732. }
  733. },
  734. ),
  735. ),
  736. videoUrl != null
  737. ? Positioned(
  738. top: 0,
  739. right: 0,
  740. child: GestureDetector(
  741. onTap: () {
  742. print(index);
  743. // imagesUrl = null;
  744. setState(() {
  745. videoUrl = null;
  746. str = null;
  747. _controller.pause();
  748. // player.reset();
  749. });
  750. },
  751. child: Icon(
  752. IconData(0xe62a, fontFamily: "myfont"),
  753. size: 24.0,
  754. color: Color(0xff999999),
  755. ),
  756. ),
  757. )
  758. : Container(
  759. child: null,
  760. )
  761. ],
  762. );
  763. },
  764. ),
  765. ),
  766. ],
  767. ),
  768. )
  769. ])),
  770. Positioned(
  771. bottom: 0,
  772. left: 0,
  773. child: Container(
  774. color:ThemeUtils.getDialogTextFieldColor(context),
  775. width: width,
  776. padding: EdgeInsets.only(
  777. top: ScreenUtil().setWidth(15),
  778. bottom: ScreenUtil().setWidth(15),
  779. left: ScreenUtil().setWidth(25),
  780. right: ScreenUtil().setWidth(25)),
  781. child: Container(
  782. height: ScreenUtil().setWidth(44),
  783. decoration: BoxDecoration(
  784. borderRadius: BorderRadius.circular(22.0),
  785. gradient: const LinearGradient(
  786. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
  787. ),
  788. child: FlatButton(
  789. // padding: EdgeInsets.all(15.0),
  790. child: Text("提交"),
  791. textColor: Colors.white,
  792. // textColor: Colors.white,
  793. onPressed: () {
  794. // getExtAddress();
  795. print(_nowDate);
  796. print(_nowDate.toString().split(" ")[0] + " " + _nowDate.toString().split(" ")[1].substring(0, 5)+":00");
  797. String time = _nowDate.toString().split(" ")[0] + " " + _nowDate.toString().split(" ")[1].substring(0, 5)+":00";
  798. print(999994);
  799. if (DateUtils.instance
  800. .getTimeStap(formartData: _nowDate.toString()) <=
  801. DateUtils.instance
  802. .getTimeStap(formartData: _oldDate.toString())) {
  803. toasts("请选择正确的出诊时间");
  804. return;
  805. }
  806. if (addressName == null || addressName == "") {
  807. toasts("请选择出诊地点");
  808. return;
  809. }
  810. // if (imagesUrl.length < 1) {
  811. // toasts("请上传图片");
  812. // return;
  813. // }
  814. String imgs = "";
  815. if(imagesUrl.length > 0){
  816. imgs = imagesUrl.join(",");
  817. }
  818. // String videoImgs = "";
  819. // if(videoUrl.length > 0){
  820. // videoImgs = videoUrl.join(",");
  821. // }
  822. if ((_formKey.currentState as FormState).validate()) {
  823. dynamic obj = {
  824. "dataTable": "2",
  825. "brandId": widget.brandId,
  826. "expression": _questionController.text,
  827. "usedMethods": _methodController.text,
  828. "imgs": imgs,
  829. "videoUrl":videoUrl,
  830. "createUserId": int.parse(
  831. flustars.SpUtil.getString(Constant.userId)),
  832. "chargerId": 1,
  833. "arrivedTime":DateUtils.instance.getTimeStap(formartData: time.toString()),
  834. // _nowDate.toString().split(" ")[0] +"T" +_nowDate.toString().split(" ")[1],
  835. // "arrivedTime":_nowDate.toString().split(" ")[0]+"T"+_nowDate.toString().split(" ")[1].substring(0, 2)+":00:00.000",
  836. "address": addressName.split(",")[0],
  837. "lat": addressName.split(",")[1],
  838. "lng": addressName.split(",")[2],
  839. };
  840. showLoading(context, "正在提交...");
  841. NewApiService().createCase(obj, onSuccess: (res) {
  842. dismissLoading(context);
  843. toasts("提交成功");
  844. FocusScope.of(context).requestFocus(FocusNode());
  845. print(res);
  846. print(999999);
  847. setDataId(res);
  848. setType("2");
  849. if(_controller!=null){
  850. _controller.pause();
  851. }
  852. NavigatorUtils.push(context,
  853. "${BbsRouter.expertList}?id=${widget.brandId}");
  854. }, onError: (code, msg) {
  855. dismissLoading(context);
  856. toasts(msg);
  857. });
  858. }
  859. },
  860. ),
  861. ),
  862. ))
  863. ]),
  864. ),
  865. );
  866. }
  867. void setDataId(int id) async {
  868. SharedPreferences prefs = await SharedPreferences.getInstance();
  869. prefs.setInt("dataId", id);
  870. }
  871. void setType(String type) async {
  872. SharedPreferences prefs = await SharedPreferences.getInstance();
  873. prefs.setString("questionType", type);
  874. }
  875. // void getExtAddress ()async{
  876. // SharedPreferences prefs = await SharedPreferences.getInstance();
  877. // extAddress = prefs.getString("extAddress");
  878. // }
  879. Widget videoPlay() {
  880. _controller = VideoPlayerController.network(
  881. Utils.getImagePath(videoUrl)
  882. // imgFontUrl + detailObj.url
  883. );
  884. double width = MediaQuery.of(context).size.width;
  885. return
  886. // Container(
  887. // width: width,
  888. // height: width*0.6,
  889. // alignment: Alignment.center,
  890. // child: FijkView(
  891. // player: player,
  892. // color: Colors.black,
  893. // fit:FijkFit.fill,
  894. // // cover: NetworkImage(detailObj.cover),
  895. // // cover: new Image(image: detailObj.cover!=null&& detailObj.cover!=""?NetworkImage(detailObj.cover):AssetImage("assets/images/video_image.png"),).image,
  896. // //
  897. // ),
  898. // );
  899. Container(
  900. padding: EdgeInsets.only(
  901. left: ScreenUtil().setWidth(15),
  902. right: ScreenUtil().setWidth(15),
  903. top: ScreenUtil().setWidth(15)),
  904. child: ClipRRect(
  905. borderRadius: BorderRadius.circular(5),
  906. child:
  907. new Chewie(
  908. controller: ChewieController(
  909. videoPlayerController:
  910. // VideoPlayerController.network(
  911. // imgFontUrl + detailObj.url
  912. // ),
  913. _controller,
  914. aspectRatio: 3 / 2,
  915. allowFullScreen:false,
  916. autoPlay: false,
  917. looping: true,
  918. // startAt: Duration(seconds: 1,minutes: 1),
  919. showControls: true,
  920. deviceOrientationsAfterFullScreen:[DeviceOrientation.portraitUp],
  921. // 占位图
  922. // placeholder: Image.network(
  923. // imgFontUrl+detailObj.cover,
  924. // fit: BoxFit.contain,
  925. // ),
  926. // 是否在 UI 构建的时候就加载视频
  927. autoInitialize: true,
  928. // 拖动条样式颜色
  929. materialProgressColors:
  930. new ChewieProgressColors(
  931. playedColor: Colors.red,
  932. handleColor: Colors.blue,
  933. backgroundColor: Colors.grey,
  934. bufferedColor: Colors.lightGreen,
  935. ),
  936. ),
  937. ),
  938. )
  939. );
  940. }
  941. }