123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993 |
- import 'dart:io';
- import 'package:chewie/chewie.dart';
- import 'package:date_format/date_format.dart';
- import 'package:flustars/flustars.dart' as flustars;
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_cupertino_date_picker/flutter_cupertino_date_picker.dart';
- import 'package:flutter_picker/flutter_picker.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:image_picker/image_picker.dart';
- import 'package:liftmanager/common/common.dart';
- import 'package:liftmanager/internal/bbs/bbs_router.dart';
- import 'package:liftmanager/internal/bbs/page/widgets.dart';
- import 'package:liftmanager/net/api_service.dart';
- import 'package:liftmanager/res/resources.dart';
- import 'package:liftmanager/routers/fluro_navigator.dart';
- import 'package:liftmanager/utils/fast_notification.dart';
- import 'package:liftmanager/utils/oss_upload.dart';
- import 'package:liftmanager/utils/theme_utils.dart';
- // 时间戳工具类
- import 'package:liftmanager/utils/time_format.dart';
- import 'package:liftmanager/utils/toast.dart';
- import 'package:liftmanager/utils/utils.dart';
- import 'package:liftmanager/widgets/app_bar.dart';
- import 'package:liftmanager/widgets/divider.dart';
- import 'package:liftmanager/widgets/selected_image_change.dart';
- import 'package:liftmanager/widgets/selected_video_change.dart';
- import 'package:orientation/orientation.dart';
- import 'package:permission_handler/permission_handler.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:video_player/video_player.dart';
- class VisitPage extends StatefulWidget {
- VisitPage(this.brandName, this.brandId);
- final String brandName;
- final String brandId;
- @override
- State<StatefulWidget> createState() {
- return VisitPageState();
- }
- }
- class VisitPageState extends State<VisitPage> {
- // NewsDetailItem item = NewsDetailItem();
- ScrollController _scrollController = new ScrollController();
- String extAddress;
- List<String> imagesUrl = [];
- // List<String> imagesUrlVideo = [];
- String videoUrl;
- String str;
- double percent = 0.0;
- String addressName = "";
- VideoPlayerController _controller;
- VideoPlayerController _controllerFile;
- ChewieController _chewieController;
- // String addressName = "湖北省武汉市洪山区武大科技园豪迈大厦,30.46139,114.414463";
- @override
- void initState() {
- super.initState();
- print(widget.brandName);
- print(widget.brandId);
- print(65656);
- FastNotification.addListener("set_address", (setAddress) {
- setState(() {
- addressName = setAddress;
- print(addressName);
- print(222222224);
- });
- });
- // getLocation();
- }
- Future<bool> requestPermission() async {
- final permissions = await PermissionHandler()
- .requestPermissions([PermissionGroup.location]);
- if (permissions[PermissionGroup.location] == PermissionStatus.granted) {
- return true;
- } else {
- toasts('需要定位权限!');
- return false;
- }
- }
- // getLocation() async {
- // if (await requestPermission()) {
- // Location location = await AmapLocation.fetchLocation();
- // String address = location.province + location.city + location.district + location.street + location.aoiName;
- // print(address);
- // setState(() {
- // addressName = address;
- // });
- // }
- // }
- @override
- void dispose() {
- _controller?.pause();
- _controller?.dispose();
- // _chewieController.videoPlayerController.dispose();
- // _chewieController.setLooping(false);
- _chewieController?.dispose();
- print('销毁了');
- // _controllerFile.dispose();
- super.dispose();
- }
- upLoadFileOnce(path) {
- showLoading(context, "正在上传...");
- NewApiService().upload(path, onSuccess: (res) {
- // imagesUrl.add(res.path);
- dismissLoading(context);
- setState(() {
- imagesUrl.add(res.pathUrl);
- });
- }, onError: (code, msg) {
- dismissLoading(context);
- toasts(msg);
- });
- }
- //视频
- upLoadFileOnceVideo(path) {
- showLoading(context, "正在上传...");
- NewApiService().upload(path, onSuccess: (res) {
- // imagesUrl.add(res.path);
- dismissLoading(context);
- setState(() {
- // videoUrl.add(res.pathUrl);
- // imagesUrlVideo.add(res.coverUrl);
- });
- }, onError: (code, msg) {
- dismissLoading(context);
- toasts(msg);
- });
- }
- ///选择图片
- void selectPicker(type) {
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return SimpleDialog(
- title: Text("选择方式"),
- children: ["拍照", '从手机相册选择'].map((String value) {
- print("$value");
- return SimpleDialogOption(
- child: Text(
- "${value}",
- style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
- ),
- onPressed: () {
- if (type == "image") {
- _getImage(value == '拍照' ? 1 : 0);
- } else if (type == "video") {
- _getVideo(value == '拍照' ? 1 : 0);
- }
- Navigator.of(context).pop();
- },
- );
- }).toList());
- });
- }
- void _getImage(int key) async {
- try {
- var _imageFile = await ImagePicker.pickImage(
- source: key == 1 ? ImageSource.camera : ImageSource.gallery,
- maxWidth: 800,
- imageQuality: 95);
- print(_imageFile);
- print(3333);
- if (_imageFile != null) {
- // images.add(_imageFile);
- upLoadFileOnce(_imageFile.path);
- // setState(() {});
- }
- } catch (e) {
- toasts("没有权限,无法打开相册!");
- }
- }
- void _getVideo(int key) async {
- print(key);
- print(333);
- try {
- await ImagePicker.pickVideo(
- source: key == 1 ? ImageSource.camera : ImageSource.gallery,
- ).then((File f) async {
- if (f != null) {
- _controllerFile = VideoPlayerController.file(f);
- _controllerFile.initialize().then((val) {
- // _controllerFile.setLooping(true);
- int seconds = _controllerFile.value.duration.inSeconds;
- print("视频时长:$seconds");
- int fileSize = f.lengthSync(); //单位B
- print("视频大小:${fileSize}");
- print("视频大小:${f.path}");
- if (seconds > 300) {
- toasts("视频时长不能大于5分钟!");
- return;
- // upLoadFileOnce(_imageFile.path);
- // setState(() {});
- } else {}
- if (fileSize > (1024 * 1000 * 50)) {
- toasts("视频不能超过50M!");
- return;
- }
- _uploadImage(f.path);
- // _uploadImage(f.path);
- }).catchError((error) {
- print(error);
- print("error");
- toasts("上传失败,不支持此格式");
- });
- }
- });
- } catch (e) {
- toasts("没有权限,无法打开相册!");
- }
- }
- void _uploadImage(filePath) async {
- showPercent(context, () {
- dismissLoading(context);
- toasts("上传失败");
- }, () {
- if (videoUrl == null && str != null) {
- setState(() {
- videoUrl = str;
- settingVideo();
- // _controller =
- // VideoPlayerController.network(Utils.getImagePath(videoUrl));
- print("videoUrl:" + videoUrl);
- dismissLoading(context);
- toasts("上传成功");
- });
- }
- });
- String uploadName = OssUtil.instance.getImageUploadName(filePath);
- await NewApiService.uploadImage(context, uploadName, filePath).then((data) {
- if (data.statusCode == 200) {
- str = NewApiUrl.URL_UPLOAD_IMAGE_OSS + "/" + uploadName;
- print("str:" + str);
- print(videoUrl);
- if (str != null) {
- Map obj = {"uploadName": uploadName, "success": true};
- FastNotification.push("percent", obj);
- }
- } else {
- Map obj = {"uploadName": uploadName, "success": false};
- FastNotification.push("percent", obj);
- }
- }).catchError((data) {
- Map obj = {"uploadName": uploadName, "success": false};
- FastNotification.push("percent", obj);
- });
- }
- settingVideo() {
- _controller?.pause();
- _controller?.dispose();
- _chewieController?.dispose();
- _controller = VideoPlayerController.network(Utils.getImagePath(videoUrl));
- _chewieController = ChewieController(
- videoPlayerController: _controller,
- isLive: true,
- // aspectRatio: 1 / 2,
- allowFullScreen: false,
- autoPlay: false,
- looping: false, //循环播放
- // startAt: Duration(seconds: 1,minutes: 1),
- showControls: true,
- deviceOrientationsAfterFullScreen: [DeviceOrientation.portraitUp],
- // 是否在 UI 构建的时候就加载视频
- autoInitialize: true,
- // 拖动条样式颜色
- materialProgressColors: new ChewieProgressColors(
- playedColor: Colors.red,
- handleColor: Colors.blue,
- backgroundColor: Colors.grey,
- bufferedColor: Colors.lightGreen,
- ),
- );
- }
- FocusNode blankNode = FocusNode();
- // 文本编辑控制
- TextEditingController _textEditingController = new TextEditingController();
- // 焦点控制
- GlobalKey _formKey = new GlobalKey<FormState>();
- TextEditingController _questionController = new TextEditingController();
- TextEditingController _methodController = new TextEditingController();
- DateTime _nowDate = DateTime.now(); //当前日期
- DateTime _oldDate = DateTime.now(); //当前日期
- DateTime _nowDateTime = DateTime.parse(formatDate(DateTime.now(),
- [yyyy, "-", mm, "-", "dd", " ", HH, ":", nn, ":", ss])); //当前日期时间
- DateTime _yearTime; //当前日期时间
- String selectDateStr;
- @override
- Widget build(BuildContext context) {
- double width = MediaQuery.of(context).size.width;
- double height = MediaQuery.of(context).size.height;
- if (width > height) {
- // SystemChrome.setPreferredOrientations([
- // DeviceOrientation.portraitUp,
- // ]);
- OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
- }
- var _datetime =
- formatDate(_nowDate, [yyyy, "-", mm, "-", dd, " ", HH, ":", nn]);
- // _nowDate, [yyyy, "-", mm, "-", dd, " ", HH, ":", nn, ":", ss]);
- // var _datetime = formatDate(_nowDate,[yyyy, "-", mm, "-", dd, " ", HH]);
- _selectYear() {
- List yearList = [];
- for (var i = 1990; i <= DateTime.now().year + 1; i++) {
- yearList.add('$i年');
- }
- yearList.add('不详');
- new Picker(
- cancelText: "取消",
- confirmText: "确认",
- adapter: PickerDataAdapter<String>(pickerdata: yearList),
- changeToFirst: true,
- hideHeader: false,
- onConfirm: (Picker picker, List value) {
- selectDateStr = picker.getSelectedValues()[0];
- // widget.onConfirm(picker.getSelectedValues()[0], value[0]);
- setState(() {});
- },
- ).showModal(this.context);
- }
- //调起datetime_picker_bottom选择器
- _cupertinoDateTimePicker({isSelectYear = false}) {
- DatePicker.showDatePicker(
- context,
- minDateTime: DateTime.parse(isSelectYear ? '1990-01-01' : '2010-05-12'),
- //起始日期
- maxDateTime: DateTime.parse(isSelectYear ? '2020-10-10' : '2021-11-25'),
- //终止日期
- //initialDateTime: DateTime.parse(formatDate(_selectedDateTime, [yyyy, "-", mm, "-", "dd", " ", HH, ":", nn, ":", ss])),
- initialDateTime: _nowDateTime,
- //当前日期时间
- // dateFormat: "yyyy年M月d日 EEE,H时", //显示格式
- dateFormat: isSelectYear ? 'yyyy年' : "yyyy年M月d日 ,H时:m分",
- //显示格式
- // dateFormat: "yyyy年M月d日 ,H时:m分:s秒", //显示格式
- locale: DateTimePickerLocale.zh_cn,
- //语言
- pickerTheme: DateTimePickerTheme(
- showTitle: true,
- ),
- pickerMode: isSelectYear
- ? DateTimePickerMode.date
- : DateTimePickerMode.datetime,
- // show TimePicker
- onCancel: () {
- debugPrint('onCancel');
- },
- onChange: (dateTime, List<int> index) {
- setState(() {
- if (!isSelectYear) {
- _nowDate = dateTime;
- } else {
- _yearTime = dateTime;
- }
- });
- },
- onConfirm: (dateTime, List<int> index) {
- setState(() {
- if (!isSelectYear) {
- _nowDate = dateTime;
- } else {
- _yearTime = dateTime;
- }
- print(_nowDate);
- print(333333);
- });
- },
- );
- }
- _leftLine() {
- return Container(
- margin: EdgeInsets.only(top: ScreenUtil().setHeight(8)),
- width: ScreenUtil().setWidth(2),
- height: ScreenUtil().setHeight(13),
- color: Color(0xFF568AFF),
- );
- }
- return Scaffold(
- resizeToAvoidBottomPadding: false, //不让键盘弹上去
- appBar: MyAppBar(
- centerTitle: "我要提问",
- ),
- body: GestureDetector(
- onTap: () {
- // 点击空白页面关闭键盘
- FocusScope.of(context).requestFocus(blankNode);
- },
- child: Stack(children: <Widget>[
- Container(
- padding: EdgeInsets.only(bottom: ScreenUtil().setWidth(80)),
- child: ListView(children: <Widget>[
- Form(
- key: _formKey, //设置globalKey,用于后面获取FormState
- // autovalidate: true, //开启自动校验
- child: Column(
- children: <Widget>[
- Container(
- padding: EdgeInsets.only(
- left: ScreenUtil().setWidth(10),
- right: ScreenUtil().setWidth(15),
- top: ScreenUtil().setWidth(10),
- bottom: ScreenUtil().setWidth(10)),
- // decoration: BoxDecoration(
- // // border: Border(
- // // bottom: BorderSide(width: 0.5, color: Colours.line),
- // // ),
- // ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(
- "电梯品牌",
- style:
- TextStyle(fontSize: ScreenUtil().setSp(14)),
- textAlign: TextAlign.start,
- ),
- Text(
- widget.brandName,
- style: TextStyle(
- color: Color(0xff999999),
- // fontSize:ScreenUtil().setSp(14)
- ),
- textAlign: TextAlign.start,
- ),
- ]),
- ),
- CzDivider(
- margin:
- EdgeInsets.only(left: ScreenUtil().setWidth(10)),
- width: double.infinity),
- SelectCell(
- leftMargin: 4,
- title: '电梯出厂日期',
- subTitle: selectDateStr,
- onTap: () {
- _selectYear();
- }),
- CzDivider(
- margin:
- EdgeInsets.only(left: ScreenUtil().setWidth(10)),
- width: double.infinity),
- Container(
- padding: EdgeInsets.only(
- left: ScreenUtil().setWidth(10),
- right: ScreenUtil().setWidth(15),
- top: ScreenUtil().setWidth(10),
- bottom: ScreenUtil().setWidth(10)),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(
- "出诊时间",
- style:
- TextStyle(fontSize: ScreenUtil().setSp(14)),
- textAlign: TextAlign.start,
- ),
- _nowDate.millisecondsSinceEpoch ==
- _oldDate.millisecondsSinceEpoch
- ? InkWell(
- onTap: _cupertinoDateTimePicker,
- child: Text(
- "请选择时间",
- style: TextStyle(
- color: Color(0xff999999),
- // fontSize:ScreenUtil().setSp(14)
- ),
- textAlign: TextAlign.start,
- ))
- : Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- InkWell(
- onTap: _cupertinoDateTimePicker,
- child: Row(
- children: <Widget>[
- Text('$_datetime'),
- Icon(Icons.arrow_drop_down)
- ],
- ),
- )
- ],
- )
- ]),
- ),
- CzDivider(
- margin:
- EdgeInsets.only(left: ScreenUtil().setWidth(10)),
- width: double.infinity),
- SelectCell(
- leftMargin: 4,
- title: '出诊地点',
- subTitle: addressName != null && addressName != ""
- ? addressName.split(",")[0]
- : "请选择",
- onTap: () {
- if (_controller != null) {
- _controller.pause();
- }
- NavigatorUtils.push(
- context, "${BbsRouter.mapChoicePoint}?type=1");
- }),
- CzDivider(
- margin:
- EdgeInsets.only(left: ScreenUtil().setWidth(10)),
- width: double.infinity),
- Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- _leftLine(),
- Container(
- padding: EdgeInsets.only(
- left: ScreenUtil().setWidth(10),
- top: ScreenUtil().setWidth(5),
- bottom: ScreenUtil().setWidth(5)),
- child: Text(
- "问题描述",
- style: TextStyle(
- // fontSize:ScreenUtil().setSp(14),miaos
- ),
- textAlign: TextAlign.left,
- ),
- ),
- ],
- ),
- Container(
- height: 100,
- padding: EdgeInsets.only(
- left: ScreenUtil().setWidth(15),
- right: ScreenUtil().setWidth(15),
- bottom: ScreenUtil().setWidth(20)),
- child: TextFormField(
- // autofocus: true,
- maxLength: 50,
- cursorColor: Color(0xffcccccc),
- controller: _questionController,
- maxLines: 5,
- decoration: InputDecoration(
- contentPadding: EdgeInsets.all(0),
- hintText: '请详细描述事故问题和现场情况',
- hintStyle: TextStyle(
- color: Color(0xffcccccc),
- ),
- focusedBorder: InputBorder.none,
- border: InputBorder.none,
- // filled: true, // 背景色
- // fillColor: Colors.cyan.withAlpha(35),
- // icon: Icon(Icons.person)
- ),
- // 校验
- validator: (val) {
- return val.trim().length > 0 ? null : "不能为空";
- }),
- ),
- CzDivider(
- margin:
- EdgeInsets.only(left: ScreenUtil().setWidth(10)),
- width: double.infinity),
- Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- _leftLine(),
- Container(
- padding: EdgeInsets.only(
- left: ScreenUtil().setWidth(10),
- top: ScreenUtil().setWidth(5),
- bottom: ScreenUtil().setWidth(5)),
- child: Text(
- "已尝试方法",
- style: TextStyle(
- // fontSize:ScreenUtil().setSp(14),
- ),
- textAlign: TextAlign.left,
- ),
- ),
- ],
- ),
- Container(
- height: 100,
- padding: EdgeInsets.only(left: 15, right: 15, bottom: 20),
- child: TextFormField(
- // autofocus: true,
- maxLength: 50,
- cursorColor: Color(0xffcccccc),
- controller: _methodController,
- maxLines: 5,
- decoration: InputDecoration(
- contentPadding: EdgeInsets.all(0),
- hintText: '请详细描述已尝试方法以及结果',
- hintStyle: TextStyle(
- color: Color(0xffcccccc),
- // fontSize: ScreenUtil().setSp(14)
- ),
- focusedBorder: InputBorder.none,
- border: InputBorder.none,
- // filled: true, // 背景色
- // fillColor: Colors.cyan.withAlpha(35),
- // icon: Icon(Icons.person)
- ),
- // 校验
- validator: (val) {
- return val.trim().length > 0 ? null : "不能为空";
- }),
- ),
- CzDivider(
- margin:
- EdgeInsets.only(left: ScreenUtil().setWidth(10)),
- width: double.infinity),
- Row(
- children: [
- _leftLine(),
- Container(
- // width: width,
- padding: EdgeInsets.only(left: 10, top: 10),
- child: Text(
- "上传图片:",
- style: TextStyle(
- fontSize: ScreenUtil().setSp(14),
- ),
- textAlign: TextAlign.left,
- ),
- ),
- ],
- ),
- Container(
- color: ThemeUtils.getTabsBg(context),
- child: GridView.builder(
- shrinkWrap: true,
- padding:
- const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
- physics: NeverScrollableScrollPhysics(),
- gridDelegate:
- SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 3, childAspectRatio: 1.18),
- itemCount:
- imagesUrl.length >= 9 ? 9 : imagesUrl.length + 1,
- itemBuilder: (_, index) {
- return Stack(
- children: <Widget>[
- Center(
- child: SelectedImage(
- image: index < imagesUrl.length
- ? imagesUrl[index]
- : null,
- index: index,
- onTap: () {
- if (index >= imagesUrl.length) {
- selectPicker("image");
- }
- FocusScope.of(context)
- .requestFocus(FocusNode());
- print(index);
- print(imagesUrl);
- }),
- ),
- index < imagesUrl.length
- ? Positioned(
- top: 0,
- right: 0,
- child: GestureDetector(
- onTap: () {
- print(index);
- imagesUrl.remove(imagesUrl[index]);
- setState(() {});
- },
- child: Icon(
- const IconData(0xe651,
- fontFamily: "Iconfont"),
- size: 24.0,
- color: Color(0xff999999),
- ),
- ))
- : Container(
- child: null,
- )
- ],
- );
- },
- )),
- CzDivider(
- margin:
- EdgeInsets.only(left: ScreenUtil().setWidth(10)),
- width: double.infinity),
- Container(
- width: width,
- padding: EdgeInsets.only(left: 15, top: 15),
- child: Text(
- "上传视频:",
- style: TextStyle(
- fontSize: ScreenUtil().setSp(14),
- ),
- textAlign: TextAlign.left,
- ),
- ),
- Container(
- width: width,
- padding: EdgeInsets.only(left: 15, bottom: 15),
- child: Text(
- "(建议时长3分钟,建议大小50M)",
- style: TextStyle(
- color: Colors.red,
- fontSize: ScreenUtil().setSp(14),
- ),
- textAlign: TextAlign.left,
- ),
- ),
- SizedBox(
- height: 20,
- ),
- // Container(
- // color: ThemeUtils.getDialogTextFieldColor(context),
- // // padding: EdgeInsets.symmetric(vertical: 20),
- // height: 150,
- // width: 150,
- // child: Stack(
- // children: <Widget>[
- // Center(
- // child: SelectedVideo(
- // image: videoUrl,
- // videoPlay: videoPlay(),
- // onTap: () {
- // if (videoUrl == null) {
- // selectPicker("video");
- // }
- // },
- // ),
- // ),
- // videoUrl != null
- // ? Positioned(
- // top: 0,
- // right: 0,
- // child: GestureDetector(
- // onTap: () {
- // // imagesUrl = null;
- // setState(() {
- // videoUrl = null;
- // str = null;
- // _controller.pause();
- // // player.reset();
- // });
- // },
- // child: Icon(
- // const IconData(0xe651,
- // fontFamily: "Iconfont"),
- // size: 24.0,
- // color: Color(0xff999999),
- // ),
- // ),
- // )
- // : Container(
- // child: null,
- // )
- // ],
- // ),
- // ),
- Container(
- color: ThemeUtils.getDialogTextFieldColor(context),
- child: GridView.builder(
- shrinkWrap: true,
- padding: const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
- physics: NeverScrollableScrollPhysics(),
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 1, childAspectRatio: 1.18),
- itemCount: 1,
- itemBuilder: (_, index) {
- return Stack(
- children: <Widget>[
- Center(
- child: SelectedVideo(
- image: videoUrl,
- index: index,
- videoPlay: videoPlay(),
- onTap: () {
- if (videoUrl == null) {
- selectPicker("video");
- }
- },
- ),
- ),
- videoUrl != null
- ? Positioned(
- top: 0,
- right: 0,
- child: GestureDetector(
- onTap: () {
- print(index);
- // imagesUrl = null;
- setState(() {
- videoUrl = null;
- str = null;
- _controller.pause();
- // player.reset();
- });
- },
- child: Icon(
- const IconData(0xe651,
- fontFamily: "Iconfont"),
- size: 24.0,
- color: Color(0xff999999),
- ),
- ),
- )
- : Container(
- child: null,
- )
- ],
- );
- },
- ),
- ),
- ],
- ),
- ),
- ]),
- ),
- Positioned(
- bottom: 0,
- left: 0,
- child: Container(
- color: ThemeUtils.getDialogTextFieldColor(context),
- width: width,
- padding: EdgeInsets.only(
- top: ScreenUtil().setWidth(15),
- bottom: ScreenUtil().setWidth(15),
- left: ScreenUtil().setWidth(25),
- right: ScreenUtil().setWidth(25)),
- child: Container(
- height: ScreenUtil().setWidth(44),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(22.0),
- color: Colours.blue_app_main
- // gradient: const LinearGradient(
- // colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
- ),
- child: FlatButton(
- // padding: EdgeInsets.all(15.0),
- child: Text("提交"),
- textColor: Colors.white,
- // textColor: Colors.white,
- onPressed: () {
- // getExtAddress();
- print(_nowDate);
- print(_nowDate.toString().split(" ")[0] +
- " " +
- _nowDate.toString().split(" ")[1].substring(0, 5) +
- ":00");
- String time = _nowDate.toString().split(" ")[0] +
- " " +
- _nowDate.toString().split(" ")[1].substring(0, 5) +
- ":00";
- print(999994);
- if (DateUtils.instance
- .getTimeStap(formartData: _nowDate.toString()) <=
- DateUtils.instance
- .getTimeStap(formartData: _oldDate.toString())) {
- toasts("请选择正确的出诊时间");
- return;
- }
- if (addressName == null || addressName == "") {
- toasts("请选择出诊地点");
- return;
- }
- // if (imagesUrl.length < 1) {
- // toasts("请上传图片");
- // return;
- // }
- String imgs = "";
- if (imagesUrl.length > 0) {
- imgs = imagesUrl.join(",");
- }
- // String videoImgs = "";
- // if(videoUrl.length > 0){
- // videoImgs = videoUrl.join(",");
- // }
- if ((_formKey.currentState as FormState).validate()) {
- dynamic obj = {
- "dataTable": "2",
- "brandId": widget.brandId,
- "expression": _questionController.text,
- "usedMethods": _methodController.text,
- "imgs": imgs,
- "videoUrl": videoUrl,
- "createUserId": int.parse(
- flustars.SpUtil.getString(Constant.userId)),
- "chargerId": 1,
- 'productionDate': selectDateStr,
- "arrivedTime": DateUtils.instance
- .getTimeStap(formartData: time.toString()),
- // _nowDate.toString().split(" ")[0] +"T" +_nowDate.toString().split(" ")[1],
- // "arrivedTime":_nowDate.toString().split(" ")[0]+"T"+_nowDate.toString().split(" ")[1].substring(0, 2)+":00:00.000",
- "address": addressName.split(",")[0],
- "lat": addressName.split(",")[1],
- "lng": addressName.split(",")[2],
- };
- showLoading(context, "正在提交...");
- NewApiService().createCase(obj, onSuccess: (res) {
- dismissLoading(context);
- toasts("提交成功");
- FocusScope.of(context).requestFocus(FocusNode());
- print(res);
- print(999999);
- setDataId(res);
- setType("2");
- if (_controller != null) {
- _controller.pause();
- }
- NavigatorUtils.push(context,
- "${BbsRouter.expertList}?id=${widget.brandId}");
- }, onError: (code, msg) {
- dismissLoading(context);
- toasts(msg);
- });
- }
- },
- ),
- ),
- ))
- ]),
- ),
- );
- }
- void setDataId(int id) async {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- prefs.setInt("dataId", id);
- }
- void setType(String type) async {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- prefs.setString("questionType", type);
- }
- // void getExtAddress ()async{
- // SharedPreferences prefs = await SharedPreferences.getInstance();
- // extAddress = prefs.getString("extAddress");
- // }
- Widget videoPlay() {
- if (_controller == null) return Container();
- return Container(
- child: ClipRRect(
- borderRadius: BorderRadius.circular(5),
- child: new Chewie(controller: _chewieController),
- ));
- }
- }
|