|
...
|
...
|
@@ -2,6 +2,7 @@ import 'dart:convert'; |
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_native_image/flutter_native_image.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
...
|
...
|
@@ -207,13 +208,32 @@ class _BookInfoPageState extends State<BookInfoPage> { |
|
|
|
}
|
|
|
|
|
|
|
|
///#相机拍照,单图选择
|
|
|
|
Future _getFromPictureOrCamera(
|
|
|
|
UploadImgModel imgModel, imageSource, int type) async {
|
|
|
|
Future _getFromPictureOrCamera(UploadImgModel imgModel, imageSource, int type,
|
|
|
|
{bool needResize = false}) async {
|
|
|
|
final pickedFile = await picker.pickImage(source: imageSource);
|
|
|
|
File compressedFile = await FlutterNativeImage.compressImage(
|
|
|
|
pickedFile.path,
|
|
|
|
quality: 50,
|
|
|
|
percentage: 50);
|
|
|
|
//从相册选取照片后进行裁剪压缩
|
|
|
|
String path;
|
|
|
|
if (needResize) {
|
|
|
|
File yourFile = File(pickedFile.path);
|
|
|
|
Uint8List afterImg = await yourFile.readAsBytes();
|
|
|
|
Uint8List newImg = await Utils.testFromFileComporessList(
|
|
|
|
context, afterImg,
|
|
|
|
needResize: true);
|
|
|
|
path = await Utils.saveImage(newImg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path == null) {
|
|
|
|
File compressedFile = await FlutterNativeImage.compressImage(
|
|
|
|
pickedFile.path,
|
|
|
|
quality: 70,
|
|
|
|
percentage: 50);
|
|
|
|
path = compressedFile.path;
|
|
|
|
}
|
|
|
|
|
|
|
|
// File compressedFile = await FlutterNativeImage.compressImage(
|
|
|
|
// pickedFile.path,
|
|
|
|
// quality: 50,
|
|
|
|
// percentage: 50);
|
|
|
|
setState(() {
|
|
|
|
if (pickedFile != null) {
|
|
|
|
imgModel.file = File(pickedFile.path);
|
|
...
|
...
|
@@ -234,7 +254,7 @@ class _BookInfoPageState extends State<BookInfoPage> { |
|
|
|
bool need = await Utils.sizeNeed(File(pickedFile.path));
|
|
|
|
File file = File(pickedFile.path);
|
|
|
|
if (need) {
|
|
|
|
file = File(compressedFile.absolute.path);
|
|
|
|
file = File(path);
|
|
|
|
}
|
|
|
|
UploadImageUtil()
|
|
|
|
.startUploadOnly(context, file, type, true, _uploadImageProvider);
|
|
...
|
...
|
@@ -243,7 +263,8 @@ class _BookInfoPageState extends State<BookInfoPage> { |
|
|
|
|
|
|
|
///添加图片UI弹出
|
|
|
|
Future _openModalBottomSheet(
|
|
|
|
context, UploadImgModel uploadImageModel, int type) async {
|
|
|
|
context, UploadImgModel uploadImageModel, int type,
|
|
|
|
{bool needResize = false}) async {
|
|
|
|
final option = await showModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
...
|
...
|
@@ -269,7 +290,8 @@ class _BookInfoPageState extends State<BookInfoPage> { |
|
|
|
// }, Permission.camera);
|
|
|
|
Utils.getPickPermission(context, () {
|
|
|
|
_getFromPictureOrCamera(
|
|
|
|
uploadImageModel, ImageSource.camera, type);
|
|
|
|
uploadImageModel, ImageSource.camera, type,
|
|
|
|
needResize: needResize);
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
Platform.isAndroid
|
|
...
|
...
|
@@ -307,7 +329,8 @@ class _BookInfoPageState extends State<BookInfoPage> { |
|
|
|
// : Permission.photos);
|
|
|
|
Utils.getPickPermission(context, () {
|
|
|
|
_getFromPictureOrCamera(
|
|
|
|
uploadImageModel, ImageSource.gallery, type);
|
|
|
|
uploadImageModel, ImageSource.gallery, type,
|
|
|
|
needResize: needResize);
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
Platform.isAndroid
|
|
...
|
...
|
@@ -496,8 +519,9 @@ class _BookInfoPageState extends State<BookInfoPage> { |
|
|
|
// _uploadImageProvider.firstImage.qiniuUrl = null;
|
|
|
|
// _uploadImageProvider.firstImage.process = 0;
|
|
|
|
// setState(() {});
|
|
|
|
_openModalBottomSheet(context,
|
|
|
|
_uploadImageProvider.firstImage, 4);
|
|
|
|
_openModalBottomSheet(
|
|
|
|
context, _uploadImageProvider.firstImage, 4,
|
|
|
|
needResize: true);
|
|
|
|
// Utils.getPickPermission(context, () {
|
|
|
|
// _getFromPictureOrCamera(
|
|
|
|
// _uploadImageProvider.firstImage,
|
|
...
|
...
|
@@ -644,7 +668,8 @@ class _BookInfoPageState extends State<BookInfoPage> { |
|
|
|
// ? Permission.storage
|
|
|
|
// : Permission.photos);
|
|
|
|
_openModalBottomSheet(
|
|
|
|
context, _uploadImageProvider.firstImage, 4);
|
|
|
|
context, _uploadImageProvider.firstImage, 4,
|
|
|
|
needResize: true);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
color: MyColours.color_d9d9d9,
|
|
...
|
...
|
@@ -750,168 +775,38 @@ class _BookInfoPageState extends State<BookInfoPage> { |
|
|
|
addLogo = !addLogo;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
Container(
|
|
|
|
height: w(210),
|
|
|
|
child: _uploadImageProvider.logo.file != null ||
|
|
|
|
(_uploadImageProvider.logo.qiniuUrl != null &&
|
|
|
|
_uploadImageProvider.logo.qiniuUrl != '')
|
|
|
|
? InkWell(
|
|
|
|
onTap: () {
|
|
|
|
double process;
|
|
|
|
String qiniuUrl;
|
|
|
|
List<String> tempList = [];
|
|
|
|
// if (title == '头像') {
|
|
|
|
process = _uploadImageProvider.logo.process;
|
|
|
|
qiniuUrl = _uploadImageProvider.logo.qiniuUrl;
|
|
|
|
// } else {
|
|
|
|
// process = _uploadImageProvider.erweima.process;
|
|
|
|
// qiniuUrl = _uploadImageProvider.erweima.qiniuUrl;
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (qiniuUrl != null && qiniuUrl != '') {
|
|
|
|
// tempList.add(qiniuUrl);
|
|
|
|
|
|
|
|
// ///没有上传完成的不可以点击
|
|
|
|
// _showPhotoView(context, 0, tempList);
|
|
|
|
_uploadImageProvider.logo.file != null ||
|
|
|
|
(_uploadImageProvider.logo.qiniuUrl != null &&
|
|
|
|
_uploadImageProvider.logo.qiniuUrl != '')
|
|
|
|
? InkWell(
|
|
|
|
onTap: () {
|
|
|
|
// double process;
|
|
|
|
String qiniuUrl;
|
|
|
|
List<String> tempList = [];
|
|
|
|
// if (title == '头像') {
|
|
|
|
// process = _uploadImageProvider.logo.process;
|
|
|
|
qiniuUrl = _uploadImageProvider.logo.qiniuUrl;
|
|
|
|
// } else {
|
|
|
|
// process = _uploadImageProvider.erweima.process;
|
|
|
|
// qiniuUrl = _uploadImageProvider.erweima.qiniuUrl;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// _uploadImageProvider.firstImage.qiniuUrl = null;
|
|
|
|
// _uploadImageProvider.firstImage.process = 0;
|
|
|
|
// setState(() {});
|
|
|
|
_openModalBottomSheet(
|
|
|
|
context, _uploadImageProvider.logo, 9);
|
|
|
|
// Utils.getPickPermission(context, () {
|
|
|
|
// _getFromPictureOrCamera(
|
|
|
|
// _uploadImageProvider.firstImage,
|
|
|
|
// ImageSource.gallery);
|
|
|
|
// },
|
|
|
|
// Platform.isAndroid
|
|
|
|
// ? Permission.storage
|
|
|
|
// : Permission.photos);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Stack(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
children: [
|
|
|
|
Stack(clipBehavior: Clip.none, children: [
|
|
|
|
_uploadImageProvider.logo.qiniuUrl !=
|
|
|
|
null &&
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.qiniuUrl !=
|
|
|
|
''
|
|
|
|
? Image.network(
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.qiniuUrl,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
width: double.infinity,
|
|
|
|
// width: ScreenUtil()
|
|
|
|
// .setWidth(imgSize * 2),
|
|
|
|
height: w(210),
|
|
|
|
)
|
|
|
|
: Image.file(
|
|
|
|
_uploadImageProvider.logo.file,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
width: double.infinity,
|
|
|
|
// width: ScreenUtil()
|
|
|
|
// .setWidth(imgSize * 2),
|
|
|
|
height: w(210),
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
child: (_uploadImageProvider
|
|
|
|
.logo.file !=
|
|
|
|
null) &&
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.process !=
|
|
|
|
1 &&
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.process !=
|
|
|
|
0.01
|
|
|
|
? Container(
|
|
|
|
width:
|
|
|
|
ScreenUtil().screenWidth,
|
|
|
|
height: w(210),
|
|
|
|
color:
|
|
|
|
MyColours.color_4D000000,
|
|
|
|
child: Center(
|
|
|
|
child: Text('上传中',
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours
|
|
|
|
.color_F8F9FD)),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Container()),
|
|
|
|
if (_uploadImageProvider.logo.process ==
|
|
|
|
1)
|
|
|
|
Positioned(
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
child: GestureDetector(
|
|
|
|
child: Image.asset(
|
|
|
|
Utils.getImgPath("delete"),
|
|
|
|
width:
|
|
|
|
ScreenUtil().setWidth(40),
|
|
|
|
height:
|
|
|
|
ScreenUtil().setWidth(40),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
//已经传到服务器,弹提醒窗口,是否删除
|
|
|
|
//修改之前有内容,则弹框
|
|
|
|
DialogUtil.cupertinoAlertDialog(
|
|
|
|
context,
|
|
|
|
title: "",
|
|
|
|
content: "是否确定删除该照片?",
|
|
|
|
lCallback: () {
|
|
|
|
print("取消");
|
|
|
|
}, rCallback: () {
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.qiniuUrl = null;
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.file = null;
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.isUpload = false;
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.process = 0.01;
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
]),
|
|
|
|
_uploadImageProvider.logo.process == 1
|
|
|
|
? Container(
|
|
|
|
width: w(150),
|
|
|
|
height: w(30),
|
|
|
|
color: MyColours.color_4D000000,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
'点击图片可以更换',
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_F8F9FD,
|
|
|
|
fontSize: font(14),
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
))
|
|
|
|
: SizedBox(),
|
|
|
|
]))
|
|
|
|
: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
// double process;
|
|
|
|
// String qiniuUrl;
|
|
|
|
// List<String> tempList = [];
|
|
|
|
// if (title == '头像') {
|
|
|
|
// process = _uploadImageProvider.touxiang.process;
|
|
|
|
// qiniuUrl = _uploadImageProvider.touxiang.qiniuUrl;
|
|
|
|
// } else {
|
|
|
|
// process = _uploadImageProvider.erweima.process;
|
|
|
|
// qiniuUrl = _uploadImageProvider.erweima.qiniuUrl;
|
|
|
|
// }
|
|
|
|
if (qiniuUrl != null && qiniuUrl != '') {
|
|
|
|
// _uploadImageProvider.logo.process = 0;
|
|
|
|
// setState(() {
|
|
|
|
|
|
|
|
// });
|
|
|
|
// setState(() {});
|
|
|
|
// tempList.add(qiniuUrl);
|
|
|
|
|
|
|
|
// if (qiniuUrl != null && qiniuUrl != '') {
|
|
|
|
// tempList.add(qiniuUrl);
|
|
|
|
// ///没有上传完成的不可以点击
|
|
|
|
// _showPhotoView(context, 0, tempList);
|
|
|
|
|
|
|
|
// ///没有上传完成的不可以点击
|
|
|
|
// _showPhotoView(context, 0, tempList);
|
|
|
|
// } else {
|
|
|
|
// _uploadImageProvider.firstImage.qiniuUrl = null;
|
|
|
|
// _uploadImageProvider.firstImage.process = 0;
|
|
|
|
// setState(() {});
|
|
|
|
_openModalBottomSheet(
|
|
|
|
context, _uploadImageProvider.logo, 9);
|
|
|
|
// Utils.getPickPermission(context, () {
|
|
|
|
// _getFromPictureOrCamera(
|
|
|
|
// _uploadImageProvider.firstImage,
|
|
...
|
...
|
@@ -920,38 +815,170 @@ class _BookInfoPageState extends State<BookInfoPage> { |
|
|
|
// Platform.isAndroid
|
|
|
|
// ? Permission.storage
|
|
|
|
// : Permission.photos);
|
|
|
|
_openModalBottomSheet(
|
|
|
|
context, _uploadImageProvider.logo, 9);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
color: MyColours.color_d9d9d9,
|
|
|
|
width: double.infinity,
|
|
|
|
height: w(180),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
// VEmptyView(80),
|
|
|
|
Image.asset(
|
|
|
|
Utils.getImgPath('add_img'),
|
|
|
|
width: w(63),
|
|
|
|
),
|
|
|
|
VEmptyView(28),
|
|
|
|
Container(
|
|
|
|
width: w(139),
|
|
|
|
height: w(60),
|
|
|
|
child: Text(
|
|
|
|
'点击上传照片',
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
height: 1.4,
|
|
|
|
color: MyColours.color_ffffff,
|
|
|
|
fontSize: font(14),
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Stack(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
children: [
|
|
|
|
Stack(clipBehavior: Clip.none, children: [
|
|
|
|
_uploadImageProvider.logo.qiniuUrl !=
|
|
|
|
null &&
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.qiniuUrl !=
|
|
|
|
''
|
|
|
|
? Center(
|
|
|
|
child: Image.network(
|
|
|
|
_uploadImageProvider.logo.qiniuUrl,
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
|
|
|
|
// width: double.infinity,
|
|
|
|
// width: ScreenUtil()
|
|
|
|
// .setWidth(imgSize * 2),
|
|
|
|
// height: w(210),
|
|
|
|
))
|
|
|
|
: Center(
|
|
|
|
child: Image.file(
|
|
|
|
_uploadImageProvider.logo.file,
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
// width: double.infinity,
|
|
|
|
// width: ScreenUtil()
|
|
|
|
// .setWidth(imgSize * 2),
|
|
|
|
// height: w(210),
|
|
|
|
)),
|
|
|
|
Positioned(
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
child: (_uploadImageProvider
|
|
|
|
.logo.file !=
|
|
|
|
null) &&
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.process !=
|
|
|
|
1 &&
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.process !=
|
|
|
|
0.01
|
|
|
|
? Container(
|
|
|
|
width: ScreenUtil().screenWidth,
|
|
|
|
height: w(210),
|
|
|
|
color: MyColours.color_4D000000,
|
|
|
|
child: Center(
|
|
|
|
child: Text('上传中',
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours
|
|
|
|
.color_F8F9FD)),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Container()),
|
|
|
|
if (_uploadImageProvider.logo.process == 1)
|
|
|
|
Positioned(
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
child: GestureDetector(
|
|
|
|
child: Image.asset(
|
|
|
|
Utils.getImgPath("delete"),
|
|
|
|
width: ScreenUtil().setWidth(40),
|
|
|
|
height: ScreenUtil().setWidth(40),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
//已经传到服务器,弹提醒窗口,是否删除
|
|
|
|
//修改之前有内容,则弹框
|
|
|
|
DialogUtil.cupertinoAlertDialog(
|
|
|
|
context,
|
|
|
|
title: "",
|
|
|
|
content: "是否确定删除该照片?",
|
|
|
|
lCallback: () {
|
|
|
|
print("取消");
|
|
|
|
}, rCallback: () {
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.qiniuUrl = null;
|
|
|
|
_uploadImageProvider.logo.file =
|
|
|
|
null;
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.isUpload = false;
|
|
|
|
_uploadImageProvider
|
|
|
|
.logo.process = 0.01;
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
]),
|
|
|
|
_uploadImageProvider.logo.process == 1
|
|
|
|
? Container(
|
|
|
|
width: w(150),
|
|
|
|
height: w(30),
|
|
|
|
color: MyColours.color_4D000000,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
'点击图片可以更换',
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_F8F9FD,
|
|
|
|
fontSize: font(14),
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
))
|
|
|
|
: SizedBox(),
|
|
|
|
]))
|
|
|
|
: Container(
|
|
|
|
height: w(210),
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
// double process;
|
|
|
|
// String qiniuUrl;
|
|
|
|
// List<String> tempList = [];
|
|
|
|
// if (title == '头像') {
|
|
|
|
// process = _uploadImageProvider.touxiang.process;
|
|
|
|
// qiniuUrl = _uploadImageProvider.touxiang.qiniuUrl;
|
|
|
|
// } else {
|
|
|
|
// process = _uploadImageProvider.erweima.process;
|
|
|
|
// qiniuUrl = _uploadImageProvider.erweima.qiniuUrl;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (qiniuUrl != null && qiniuUrl != '') {
|
|
|
|
// tempList.add(qiniuUrl);
|
|
|
|
|
|
|
|
// ///没有上传完成的不可以点击
|
|
|
|
// _showPhotoView(context, 0, tempList);
|
|
|
|
// } else {
|
|
|
|
// Utils.getPickPermission(context, () {
|
|
|
|
// _getFromPictureOrCamera(
|
|
|
|
// _uploadImageProvider.firstImage,
|
|
|
|
// ImageSource.gallery);
|
|
|
|
// },
|
|
|
|
// Platform.isAndroid
|
|
|
|
// ? Permission.storage
|
|
|
|
// : Permission.photos);
|
|
|
|
_openModalBottomSheet(
|
|
|
|
context, _uploadImageProvider.logo, 9);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
color: MyColours.color_d9d9d9,
|
|
|
|
width: double.infinity,
|
|
|
|
height: w(180),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
// VEmptyView(80),
|
|
|
|
Image.asset(
|
|
|
|
Utils.getImgPath('add_img'),
|
|
|
|
width: w(63),
|
|
|
|
),
|
|
|
|
VEmptyView(28),
|
|
|
|
Container(
|
|
|
|
width: w(139),
|
|
|
|
height: w(60),
|
|
|
|
child: Text(
|
|
|
|
'点击上传照片',
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
height: 1.4,
|
|
|
|
color: MyColours.color_ffffff,
|
|
|
|
fontSize: font(14),
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
|
|
|
|
VEmptyView(16)
|
|
|
|
]),
|
...
|
...
|
|