|
...
|
...
|
@@ -2,6 +2,7 @@ import 'dart:io'; |
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/rendering.dart';
|
|
|
|
import 'package:flutter_ijkplayer/flutter_ijkplayer.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:one_key/models/upload_img_model.dart';
|
|
...
|
...
|
@@ -72,6 +73,8 @@ class _VideoPickerWidgetState extends DisposableState<VideoPickerWidget> { |
|
|
|
//////#相机拍照,单图选择
|
|
|
|
Future _getImageFromPictureOrCamera(ImageSource imageSource) async {
|
|
|
|
final pickedFile = await picker.getImage(source: imageSource);
|
|
|
|
// String ddd = Utils.getPicSuffix(pickedFile.path);
|
|
|
|
// print(ddd);
|
|
|
|
setState(() {
|
|
|
|
if (pickedFile != null) {
|
|
|
|
UploadImgModel imgModel = UploadImgModel();
|
|
...
|
...
|
@@ -98,7 +101,8 @@ class _VideoPickerWidgetState extends DisposableState<VideoPickerWidget> { |
|
|
|
Future _getVideoFromPictureOrCamera(ImageSource imageSource) async {
|
|
|
|
final pickedFile = await picker.getVideo(
|
|
|
|
source: imageSource, maxDuration: const Duration(seconds: 15));
|
|
|
|
|
|
|
|
String ddd = Utils.getPicSuffix(pickedFile.path);
|
|
|
|
print(ddd);
|
|
|
|
await VideoCompress.setLogLevel(0);
|
|
|
|
final info = await VideoCompress.getMediaInfo(pickedFile.path);
|
|
|
|
String duration = '00';
|
|
...
|
...
|
@@ -352,240 +356,255 @@ class _VideoPickerWidgetState extends DisposableState<VideoPickerWidget> { |
|
|
|
|
|
|
|
/// 九宫格
|
|
|
|
Widget _getGridImg(count, context, isLinjie) {
|
|
|
|
return GridView.builder(
|
|
|
|
controller: widget.scrollController,
|
|
|
|
// padding: EdgeInsets.only(top: ScreenUtil().getAdapterSize(10)),
|
|
|
|
shrinkWrap: true,
|
|
|
|
itemCount: count,
|
|
|
|
//SliverGridDelegateWithFixedCrossAxisCount 构建一个横轴固定数量Widget
|
|
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
|
|
//横轴元素个数
|
|
|
|
crossAxisCount: 3,
|
|
|
|
//纵轴间距
|
|
|
|
mainAxisSpacing: ScreenUtil().setWidth(30),
|
|
|
|
//横轴间距
|
|
|
|
crossAxisSpacing: ScreenUtil().setWidth(30),
|
|
|
|
//子组件宽高长度比例
|
|
|
|
childAspectRatio: 1.0),
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
var linjie = widget.maxImageNumber;
|
|
|
|
if (isLinjie) {
|
|
|
|
linjie = widget.maxImageNumber - 2;
|
|
|
|
}
|
|
|
|
if (index == count - 2 && index < linjie) {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () {
|
|
|
|
// 触摸收起键盘
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
|
|
_openModalBottomSheet(context, FileType.image);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
width: ScreenUtil().setWidth(90 * 2),
|
|
|
|
height: ScreenUtil().setWidth(90 * 2),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: MyColours.color_E0E0E0,
|
|
|
|
width: ScreenUtil().setWidth(2)),
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
VEmptyView(74),
|
|
|
|
Image.asset(
|
|
|
|
Utils.getImgPath('add_image'),
|
|
|
|
width: ScreenUtil().setWidth(32),
|
|
|
|
height: ScreenUtil().setWidth(32),
|
|
|
|
return Container(
|
|
|
|
height: ScreenUtil().setWidth(90 * 2),
|
|
|
|
child: ListView.builder(
|
|
|
|
controller: widget.scrollController,
|
|
|
|
// padding: EdgeInsets.only(top: ScreenUtil().getAdapterSize(10)),
|
|
|
|
shrinkWrap: true,
|
|
|
|
itemCount: count,
|
|
|
|
//列表高度
|
|
|
|
itemExtent: ScreenUtil().setWidth(100 * 2),
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(70)),
|
|
|
|
//SliverGridDelegateWithFixedCrossAxisCount 构建一个横轴固定数量Widget
|
|
|
|
// gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
|
|
// //横轴元素个数
|
|
|
|
// crossAxisCount: 3,
|
|
|
|
// //纵轴间距
|
|
|
|
// mainAxisSpacing: ScreenUtil().setWidth(30),
|
|
|
|
// //横轴间距
|
|
|
|
// crossAxisSpacing: ScreenUtil().setWidth(30),
|
|
|
|
// //子组件宽高长度比例
|
|
|
|
// childAspectRatio: 1.0),
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
var linjie = widget.maxImageNumber;
|
|
|
|
if (isLinjie) {
|
|
|
|
linjie = widget.maxImageNumber - 2;
|
|
|
|
}
|
|
|
|
if (index == count - 2 && index < linjie) {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () {
|
|
|
|
// 触摸收起键盘
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
|
|
_openModalBottomSheet(context, FileType.image);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
width: ScreenUtil().setWidth(110 * 2),
|
|
|
|
height: ScreenUtil().setWidth(90 * 2),
|
|
|
|
margin: EdgeInsets.only(right: ScreenUtil().setWidth(20)),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: MyColours.color_E0E0E0,
|
|
|
|
width: ScreenUtil().setWidth(2)),
|
|
|
|
),
|
|
|
|
VEmptyView(10),
|
|
|
|
Text(
|
|
|
|
'添加图片',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_999999),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (index == count - 1 && index <= linjie) {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () {
|
|
|
|
// 触摸收起键盘
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
|
|
_openModalBottomSheet(context, FileType.video);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
width: ScreenUtil().setWidth(90 * 2),
|
|
|
|
height: ScreenUtil().setWidth(90 * 2),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: MyColours.color_E0E0E0,
|
|
|
|
width: ScreenUtil().setWidth(2)),
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
VEmptyView(74),
|
|
|
|
Image.asset(
|
|
|
|
Utils.getImgPath('add_image'),
|
|
|
|
width: ScreenUtil().setWidth(32),
|
|
|
|
height: ScreenUtil().setWidth(32),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
VEmptyView(46),
|
|
|
|
Image.asset(
|
|
|
|
Utils.getImgPath('add_image'),
|
|
|
|
width: ScreenUtil().setWidth(44),
|
|
|
|
height: ScreenUtil().setWidth(40),
|
|
|
|
),
|
|
|
|
VEmptyView(10),
|
|
|
|
Text(
|
|
|
|
'上传照片',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_999999),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (index == count - 1 && index <= linjie) {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () {
|
|
|
|
// 触摸收起键盘
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
|
|
_openModalBottomSheet(context, FileType.video);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
width: ScreenUtil().setWidth(110 * 2),
|
|
|
|
height: ScreenUtil().setWidth(90 * 2),
|
|
|
|
margin: EdgeInsets.only(right: ScreenUtil().setWidth(20)),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: MyColours.color_E0E0E0,
|
|
|
|
width: ScreenUtil().setWidth(2)),
|
|
|
|
),
|
|
|
|
VEmptyView(10),
|
|
|
|
Text(
|
|
|
|
'添加视频',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_999999),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
VEmptyView(46),
|
|
|
|
Image.asset(
|
|
|
|
Utils.getImgPath('add_video'),
|
|
|
|
width: ScreenUtil().setWidth(44),
|
|
|
|
height: ScreenUtil().setWidth(40),
|
|
|
|
),
|
|
|
|
VEmptyView(10),
|
|
|
|
Text(
|
|
|
|
'上传视频',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_999999),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return widget.model.imageListDenvironment.length < 1
|
|
|
|
? Text('')
|
|
|
|
: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
if (widget.model.imageListDenvironment[index].process ==
|
|
|
|
1) {
|
|
|
|
widget.model.imageQiniuUrlList = [];
|
|
|
|
if (widget.model.imageListDenvironment[index].qiniuUrl !=
|
|
|
|
null) {
|
|
|
|
if (widget
|
|
|
|
.model.imageListDenvironment[index].fileType ==
|
|
|
|
FileType.image) {
|
|
|
|
List<UploadImgModel> temp = [];
|
|
|
|
temp.addAll(widget.model.imageListDenvironment);
|
|
|
|
temp.removeWhere(
|
|
|
|
(element) => element.fileType == FileType.video);
|
|
|
|
for (int i = 0; i < temp.length; i++) {
|
|
|
|
widget.model.imageQiniuUrlList
|
|
|
|
.add(temp[i].qiniuUrl);
|
|
|
|
}
|
|
|
|
return widget.model.imageListDenvironment.length < 1
|
|
|
|
? Text('')
|
|
|
|
: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
if (widget.model.imageListDenvironment[index].process ==
|
|
|
|
1) {
|
|
|
|
widget.model.imageQiniuUrlList = [];
|
|
|
|
if (widget.model.imageListDenvironment[index]
|
|
|
|
.qiniuUrl !=
|
|
|
|
null) {
|
|
|
|
if (widget.model.imageListDenvironment[index]
|
|
|
|
.fileType ==
|
|
|
|
FileType.image) {
|
|
|
|
List<UploadImgModel> temp = [];
|
|
|
|
temp.addAll(widget.model.imageListDenvironment);
|
|
|
|
temp.removeWhere((element) =>
|
|
|
|
element.fileType == FileType.video);
|
|
|
|
for (int i = 0; i < temp.length; i++) {
|
|
|
|
widget.model.imageQiniuUrlList
|
|
|
|
.add(temp[i].qiniuUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
///没有上传完成的不可以点击
|
|
|
|
_showPhotoView(
|
|
|
|
context, index, widget.model.imageQiniuUrlList);
|
|
|
|
} else if (widget
|
|
|
|
.model.imageListDenvironment[index].fileType ==
|
|
|
|
FileType.video) {
|
|
|
|
NavigatorUtil.goPlayVideoPage(context,
|
|
|
|
urlStr: widget
|
|
|
|
.model.imageListDenvironment[index].qiniuUrl);
|
|
|
|
///没有上传完成的不可以点击
|
|
|
|
_showPhotoView(context, index,
|
|
|
|
widget.model.imageQiniuUrlList);
|
|
|
|
} else if (widget.model.imageListDenvironment[index]
|
|
|
|
.fileType ==
|
|
|
|
FileType.video) {
|
|
|
|
NavigatorUtil.goPlayVideoPage(context,
|
|
|
|
urlStr: widget.model
|
|
|
|
.imageListDenvironment[index].qiniuUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Stack(
|
|
|
|
alignment: Alignment.topRight,
|
|
|
|
},
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
widget.model.imageListDenvironment[index].fileType ==
|
|
|
|
FileType.image
|
|
|
|
? Image.file(
|
|
|
|
widget
|
|
|
|
.model.imageListDenvironment[index].file,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
width: ScreenUtil().setWidth(100 * 2),
|
|
|
|
height: ScreenUtil().setWidth(100 * 2),
|
|
|
|
)
|
|
|
|
: Image.file(
|
|
|
|
widget.model.imageListDenvironment[index]
|
|
|
|
.thumbnailPath,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
width: ScreenUtil().setWidth(100 * 2),
|
|
|
|
height: ScreenUtil().setWidth(100 * 2),
|
|
|
|
)
|
|
|
|
// : FutureBuilder(
|
|
|
|
// //显示缩略图
|
|
|
|
// future: _initializeVideoPlayerFuture,
|
|
|
|
// builder: (context, snapshot) {
|
|
|
|
// print(snapshot.connectionState);
|
|
|
|
// if (snapshot.hasError)
|
|
|
|
// print(snapshot.error);
|
|
|
|
// if (snapshot.connectionState ==
|
|
|
|
// ConnectionState.done) {
|
|
|
|
// return Container(
|
|
|
|
// // width: ScreenUtil().setWidth(225),
|
|
|
|
// child: AspectRatio(
|
|
|
|
// aspectRatio: 1 / 1,
|
|
|
|
Stack(
|
|
|
|
alignment: Alignment.topRight,
|
|
|
|
children: [
|
|
|
|
widget.model.imageListDenvironment[index]
|
|
|
|
.fileType ==
|
|
|
|
FileType.image
|
|
|
|
? Image.file(
|
|
|
|
widget.model.imageListDenvironment[index]
|
|
|
|
.file,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
width: ScreenUtil().setWidth(90 * 2),
|
|
|
|
height: ScreenUtil().setWidth(90 * 2),
|
|
|
|
)
|
|
|
|
: Image.file(
|
|
|
|
widget.model.imageListDenvironment[index]
|
|
|
|
.thumbnailPath,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
width: ScreenUtil().setWidth(90 * 2),
|
|
|
|
height: ScreenUtil().setWidth(90 * 2),
|
|
|
|
)
|
|
|
|
// : FutureBuilder(
|
|
|
|
// //显示缩略图
|
|
|
|
// future: _initializeVideoPlayerFuture,
|
|
|
|
// builder: (context, snapshot) {
|
|
|
|
// print(snapshot.connectionState);
|
|
|
|
// if (snapshot.hasError)
|
|
|
|
// print(snapshot.error);
|
|
|
|
// if (snapshot.connectionState ==
|
|
|
|
// ConnectionState.done) {
|
|
|
|
// return Container(
|
|
|
|
// // width: ScreenUtil().setWidth(225),
|
|
|
|
// child: AspectRatio(
|
|
|
|
// aspectRatio: 1 / 1,
|
|
|
|
|
|
|
|
// // aspectRatio: _controller.value.aspectRatio,
|
|
|
|
// child: VideoPlayer(_controller),
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
// } else {
|
|
|
|
// return Center(
|
|
|
|
// child: CircularProgressIndicator(),
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
,
|
|
|
|
Offstage(
|
|
|
|
offstage: widget.model.imageListDenvironment[index]
|
|
|
|
.process <
|
|
|
|
1,
|
|
|
|
child: GestureDetector(
|
|
|
|
child: Image.asset(
|
|
|
|
Utils.getImgPath("delete"),
|
|
|
|
width: ScreenUtil().setWidth(40),
|
|
|
|
height: ScreenUtil().setWidth(40),
|
|
|
|
// // aspectRatio: _controller.value.aspectRatio,
|
|
|
|
// child: VideoPlayer(_controller),
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
// } else {
|
|
|
|
// return Center(
|
|
|
|
// child: CircularProgressIndicator(),
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
,
|
|
|
|
Offstage(
|
|
|
|
offstage: widget.model
|
|
|
|
.imageListDenvironment[index].process <
|
|
|
|
1,
|
|
|
|
child: GestureDetector(
|
|
|
|
child: Image.asset(
|
|
|
|
Utils.getImgPath("delete"),
|
|
|
|
width: ScreenUtil().setWidth(40),
|
|
|
|
height: ScreenUtil().setWidth(40),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
//点击删除按钮
|
|
|
|
setState(() {
|
|
|
|
widget.model.imageListDenvironment
|
|
|
|
.removeWhere((element) =>
|
|
|
|
element ==
|
|
|
|
widget.model
|
|
|
|
.imageListDenvironment[
|
|
|
|
index]);
|
|
|
|
widget.model.imageQiniuUrlList
|
|
|
|
.removeWhere((element) =>
|
|
|
|
element ==
|
|
|
|
widget.model
|
|
|
|
.imageQiniuUrlList[index]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
//点击删除按钮
|
|
|
|
setState(() {
|
|
|
|
widget.model.imageListDenvironment
|
|
|
|
.removeWhere((element) =>
|
|
|
|
element ==
|
|
|
|
widget.model
|
|
|
|
.imageListDenvironment[index]);
|
|
|
|
widget.model.imageQiniuUrlList.removeWhere(
|
|
|
|
(element) =>
|
|
|
|
element ==
|
|
|
|
widget
|
|
|
|
.model.imageQiniuUrlList[index]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
// Offstage(
|
|
|
|
// offstage: widget.model.imageListDenvironment[index].process == 1,
|
|
|
|
// child: Progress(widget.model.imageListDenvironment[index].process),
|
|
|
|
// ),
|
|
|
|
widget.model.imageListDenvironment[index].process == 1
|
|
|
|
? widget.model.imageListDenvironment[index]
|
|
|
|
.fileType ==
|
|
|
|
FileType.video
|
|
|
|
? Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Image.asset(
|
|
|
|
Utils.getImgPath('play'),
|
|
|
|
width: ScreenUtil().setWidth(60),
|
|
|
|
))
|
|
|
|
: Container()
|
|
|
|
: Progress(
|
|
|
|
widget.model.imageListDenvironment[index]
|
|
|
|
.process,
|
|
|
|
size: 90.0,
|
|
|
|
),
|
|
|
|
// widget.model.imageListDenvironment[index].fileType ==
|
|
|
|
// FileType.video
|
|
|
|
// ? Align(
|
|
|
|
// alignment: Alignment.bottomRight,
|
|
|
|
// child: Padding(
|
|
|
|
// padding: EdgeInsets.only(
|
|
|
|
// bottom: ScreenUtil().setWidth(10),
|
|
|
|
// right: ScreenUtil().setWidth(10)),
|
|
|
|
// child: Text(
|
|
|
|
// '00:${widget.model.imageListDenvironment[index].duration}',
|
|
|
|
// style: TextStyle(
|
|
|
|
// color: MyColours.color_333333,
|
|
|
|
// fontSize: ScreenUtil().setSp(24)),
|
|
|
|
// )),
|
|
|
|
// )
|
|
|
|
// : Container()
|
|
|
|
],
|
|
|
|
),
|
|
|
|
// Offstage(
|
|
|
|
// offstage: widget.model.imageListDenvironment[index].process == 1,
|
|
|
|
// child: Progress(widget.model.imageListDenvironment[index].process),
|
|
|
|
// ),
|
|
|
|
widget.model.imageListDenvironment[index].process == 1
|
|
|
|
? widget.model.imageListDenvironment[index]
|
|
|
|
.fileType ==
|
|
|
|
FileType.video
|
|
|
|
? Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Image.asset(
|
|
|
|
Utils.getImgPath('check_g'),
|
|
|
|
width: ScreenUtil().setWidth(40),
|
|
|
|
))
|
|
|
|
: Container()
|
|
|
|
: Progress(widget
|
|
|
|
.model.imageListDenvironment[index].process),
|
|
|
|
widget.model.imageListDenvironment[index].fileType ==
|
|
|
|
FileType.video
|
|
|
|
? Align(
|
|
|
|
alignment: Alignment.bottomRight,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
bottom: ScreenUtil().setWidth(10),
|
|
|
|
right: ScreenUtil().setWidth(10)),
|
|
|
|
child: Text(
|
|
|
|
'00:${widget.model.imageListDenvironment[index].duration}',
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(24)),
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
: Container()
|
|
|
|
],
|
|
|
|
));
|
|
|
|
});
|
|
|
|
));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|