|
...
|
...
|
@@ -2,15 +2,23 @@ import 'dart:io'; |
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
import 'package:one_key/pages/online_check/photo_view_wiget.dart';
|
|
|
|
|
|
|
|
import 'package:one_key/provider/online_check_edit_provider.dart';
|
|
|
|
import 'package:one_key/res/colors.dart';
|
|
|
|
import 'package:one_key/utils/utils.dart';
|
|
|
|
import 'package:one_key/widgets/MyDivider.dart';
|
|
|
|
import 'package:one_key/widgets/v_empty_view.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
import 'package:video_player/video_player.dart';
|
|
|
|
|
|
|
|
final int MAX_IMAGE_NUMBER = 9;
|
|
|
|
typedef void OnPickImageCallback(
|
|
|
|
double maxWidth, double maxHeight, int quality);
|
|
|
|
|
|
|
|
class ImgPickerWidget extends StatelessWidget {
|
|
|
|
class ImgPickerWidget extends StatefulWidget {
|
|
|
|
final ScrollController scrollController;
|
|
|
|
final Color borderColor;
|
|
|
|
final ValueChanged onChange;
|
|
...
|
...
|
@@ -21,46 +29,121 @@ class ImgPickerWidget extends StatelessWidget { |
|
|
|
this.onChange})
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_ImgPickerWidgetState createState() => _ImgPickerWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ImgPickerWidgetState extends State<ImgPickerWidget> {
|
|
|
|
File _image;
|
|
|
|
final picker = ImagePicker();
|
|
|
|
OnlineCheckEditProvider _onlineCheckEditProvider;
|
|
|
|
|
|
|
|
//相册 相机
|
|
|
|
Future _getFromPictureOrCamera(context, imageSource) async {
|
|
|
|
// File image = await ImagePicker.pickImage(
|
|
|
|
// source: imageSource,
|
|
|
|
// );
|
|
|
|
// if (image != null) {
|
|
|
|
// _provider.imageList.add(image);
|
|
|
|
// _provider.notifyListeners();
|
|
|
|
// }
|
|
|
|
// _provider.uploadTravelReleaseImg(image);
|
|
|
|
// Future _getFromPictureOrCamera(context, imageSource) async {
|
|
|
|
// File image = await picker.getImage(
|
|
|
|
// source: imageSource,
|
|
|
|
// );
|
|
|
|
// if (image != null) {
|
|
|
|
// _provider.imageList.add(image);
|
|
|
|
// _provider.notifyListeners();
|
|
|
|
// }
|
|
|
|
// // _provider.uploadTravelReleaseImg(image);
|
|
|
|
// }
|
|
|
|
|
|
|
|
Future _getFromPictureOrCamera(imageSource) async {
|
|
|
|
final pickedFile = await picker.getImage(source: imageSource);
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
if (pickedFile != null) {
|
|
|
|
_image = File(pickedFile.path);
|
|
|
|
_onlineCheckEditProvider.imageList.add(_image);
|
|
|
|
_onlineCheckEditProvider.notifyListeners();
|
|
|
|
} else {
|
|
|
|
print('No image selected.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _openModalBottomSheet(context) async {
|
|
|
|
final option = await showModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
height: 200.0,
|
|
|
|
// height: ScreenUtil().setWidth(180 * 2),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: MyColours.color_ffffff,
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(ScreenUtil().setWidth(24)),
|
|
|
|
topRight: Radius.circular(ScreenUtil().setWidth(24)))),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
|
|
|
title: Text('拍照', textAlign: TextAlign.center),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
_getFromPictureOrCamera(context, ImageSource.camera);
|
|
|
|
_getFromPictureOrCamera(ImageSource.camera);
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
vertical: ScreenUtil().setWidth(18 * 2)),
|
|
|
|
child: Text(
|
|
|
|
'拍摄',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(32),
|
|
|
|
color: MyColours.color_353535,
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
MyDivider(
|
|
|
|
double.infinity,
|
|
|
|
ScreenUtil().setWidth(2),
|
|
|
|
color: MyColours.color_EEEEEE,
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('从相册选择', textAlign: TextAlign.center),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
_getFromPictureOrCamera(context, ImageSource.gallery);
|
|
|
|
_getFromPictureOrCamera(ImageSource.gallery);
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
vertical: ScreenUtil().setWidth(18 * 2)),
|
|
|
|
child: Text(
|
|
|
|
'从相册选择',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(32),
|
|
|
|
color: MyColours.color_353535,
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('取消', textAlign: TextAlign.center),
|
|
|
|
MyDivider(
|
|
|
|
double.infinity,
|
|
|
|
ScreenUtil().setWidth(10),
|
|
|
|
color: MyColours.color_EEEEEE,
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pop(context, '取消');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
vertical: ScreenUtil().setWidth(18 * 2)),
|
|
|
|
child: Text(
|
|
|
|
'取消',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(32),
|
|
|
|
color: MyColours.color_353535,
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
...
|
...
|
@@ -71,7 +154,7 @@ class ImgPickerWidget extends StatelessWidget { |
|
|
|
OnlineCheckEditProvider _provider =
|
|
|
|
Provider.of<OnlineCheckEditProvider>(context, listen: false);
|
|
|
|
return GridView.builder(
|
|
|
|
controller: scrollController,
|
|
|
|
controller: widget.scrollController,
|
|
|
|
// padding: EdgeInsets.only(top: ScreenUtil().getAdapterSize(10)),
|
|
|
|
shrinkWrap: true,
|
|
|
|
itemCount: count,
|
|
...
|
...
|
@@ -100,16 +183,24 @@ class ImgPickerWidget extends StatelessWidget { |
|
|
|
width: ScreenUtil().setWidth(90 * 2),
|
|
|
|
height: ScreenUtil().setWidth(90 * 2),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: MyColours.color_E0E0E0,
|
|
|
|
width: ScreenUtil().setWidth(2)),
|
|
|
|
color: Theme.of(context).backgroundColor),
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
VEmptyView(10),
|
|
|
|
Text(
|
|
|
|
'添加照片',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_999999),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)),
|
|
...
|
...
|
@@ -117,13 +208,51 @@ class ImgPickerWidget extends StatelessWidget { |
|
|
|
}
|
|
|
|
return _provider.imageList.length < 1
|
|
|
|
? Text('')
|
|
|
|
: Image.file(_provider.imageList[index], fit: BoxFit.cover);
|
|
|
|
: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
_showPhotoView(context, index, _provider.imageList[index]);
|
|
|
|
},
|
|
|
|
child:
|
|
|
|
Image.file(_provider.imageList[index], fit: BoxFit.cover),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//查看大图
|
|
|
|
_showPhotoView(BuildContext context, int index, List imgs,
|
|
|
|
{isShow = false, List dashName}) async {
|
|
|
|
// if (imgs.length == 1 &&
|
|
|
|
// imgs[0] ==
|
|
|
|
// 'http://nosqn.colorcun.com/custom/lite-online/image/def-banner.png') {
|
|
|
|
// imgs[0] = 'http://nosqn.colorcun.com/app/seller-hj-empty.png';
|
|
|
|
// }
|
|
|
|
Utils.setBarStatus(false, color: Colors.black);
|
|
|
|
dynamic result = await showGeneralDialog(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: false,
|
|
|
|
// barrierColor: Colors.red,
|
|
|
|
barrierLabel:
|
|
|
|
MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
|
|
transitionDuration: const Duration(milliseconds: 150),
|
|
|
|
pageBuilder: (BuildContext context, Animation animation,
|
|
|
|
Animation secondaryAnimation) {
|
|
|
|
Widget child = Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
PhotoPreview(
|
|
|
|
initialIndex: index,
|
|
|
|
photoList: imgs,
|
|
|
|
isShow: isShow,
|
|
|
|
dashName: dashName)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
return child;
|
|
|
|
});
|
|
|
|
Utils.setBarStatus(true, color: Colors.white);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
OnlineCheckEditProvider _provider =
|
|
|
|
_onlineCheckEditProvider =
|
|
|
|
Provider.of<OnlineCheckEditProvider>(context, listen: true);
|
|
|
|
return Container(
|
|
|
|
width: double.infinity,
|
|
...
|
...
|
@@ -158,11 +287,13 @@ class ImgPickerWidget extends StatelessWidget { |
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.all(ScreenUtil().setWidth(40)),
|
|
|
|
child: _getGridImg(
|
|
|
|
_provider.imageList.length < MAX_IMAGE_NUMBER
|
|
|
|
? _provider.imageList.length + 1
|
|
|
|
: _provider.imageList.length,
|
|
|
|
_onlineCheckEditProvider.imageList.length < MAX_IMAGE_NUMBER
|
|
|
|
? _onlineCheckEditProvider.imageList.length + 1
|
|
|
|
: _onlineCheckEditProvider.imageList.length,
|
|
|
|
context,
|
|
|
|
_provider.imageList.length == MAX_IMAGE_NUMBER ? true : false),
|
|
|
|
_onlineCheckEditProvider.imageList.length == MAX_IMAGE_NUMBER
|
|
|
|
? true
|
|
|
|
: false),
|
|
|
|
)
|
|
|
|
// _getGridImg(1, context)
|
|
|
|
],
|
...
|
...
|
|