|
|
@ -8,10 +8,11 @@ import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:aku_community_manager/const/resource.dart';
|
|
|
|
import 'package:aku_community_manager/const/resource.dart';
|
|
|
|
import 'package:velocity_x/velocity_x.dart';
|
|
|
|
import 'package:velocity_x/velocity_x.dart';
|
|
|
|
|
|
|
|
import 'package:aku_community_manager/utils/extension/list_extension.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class AkuPickImageWidget extends StatefulWidget {
|
|
|
|
class AkuPickImageWidget extends StatefulWidget {
|
|
|
|
final double size;
|
|
|
|
final double size;
|
|
|
|
final Function(File file) onChanged;
|
|
|
|
final Function(List<File> files) onChanged;
|
|
|
|
AkuPickImageWidget({Key key, this.size, this.onChanged}) : super(key: key);
|
|
|
|
AkuPickImageWidget({Key key, this.size, this.onChanged}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
@ -19,71 +20,81 @@ class AkuPickImageWidget extends StatefulWidget {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _AkuPickImageWidgetState extends State<AkuPickImageWidget> {
|
|
|
|
class _AkuPickImageWidgetState extends State<AkuPickImageWidget> {
|
|
|
|
File _file;
|
|
|
|
List<File> _files = [];
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return _file != null
|
|
|
|
return Row(
|
|
|
|
? Stack(children: [
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
..._files?.map((e) => showImage(e))?.toList(),
|
|
|
|
|
|
|
|
GestureDetector(
|
|
|
|
|
|
|
|
onTap: () async {
|
|
|
|
|
|
|
|
await akuPickImage().then(
|
|
|
|
|
|
|
|
(value) => _files.add(
|
|
|
|
|
|
|
|
File(value.path),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
widget.onChanged(_files);
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
child: DottedBorder(
|
|
|
|
|
|
|
|
color: Color(0xFF999999),
|
|
|
|
|
|
|
|
borderType: BorderType.RRect,
|
|
|
|
|
|
|
|
strokeWidth: 2.w,
|
|
|
|
|
|
|
|
dashPattern: [6, 3],
|
|
|
|
|
|
|
|
radius: Radius.circular(8.w),
|
|
|
|
|
|
|
|
child: Container(
|
|
|
|
width: widget.size ?? 160.w,
|
|
|
|
width: widget.size ?? 160.w,
|
|
|
|
height: widget.size ?? 160.w,
|
|
|
|
height: widget.size ?? 160.w,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
child: Column(
|
|
|
|
borderRadius: BorderRadius.circular(8.w),
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
color: kBackgroundColor),
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
child: Image.file(_file),
|
|
|
|
children: [
|
|
|
|
),
|
|
|
|
Image.asset(
|
|
|
|
Positioned(
|
|
|
|
R.ASSETS_MANAGE_IC_IMAGE_PNG,
|
|
|
|
top: 8.w,
|
|
|
|
width: 60.w,
|
|
|
|
right: 8.w,
|
|
|
|
height: 60.w,
|
|
|
|
child: Container(
|
|
|
|
color: Color(0xFF999999),
|
|
|
|
width: 40.w,
|
|
|
|
),
|
|
|
|
height: 40.w,
|
|
|
|
4.w.heightBox,
|
|
|
|
child: Icon(
|
|
|
|
'上传图片'.text.color(kTextSubColor).size(22.sp).bold.make(),
|
|
|
|
CupertinoIcons.xmark,
|
|
|
|
],
|
|
|
|
size: 20.w,
|
|
|
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
|
|
borderRadius: BorderRadius.circular(20.w),
|
|
|
|
|
|
|
|
color: Color(0xFF000000),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
).onTap(() {
|
|
|
|
|
|
|
|
_file = null;
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
: GestureDetector(
|
|
|
|
|
|
|
|
onTap: () async {
|
|
|
|
|
|
|
|
await akuPickImage().then((value) => _file = File(value.path));
|
|
|
|
|
|
|
|
widget.onChanged(_file);
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
child: DottedBorder(
|
|
|
|
|
|
|
|
color: Color(0xFF999999),
|
|
|
|
|
|
|
|
borderType: BorderType.RRect,
|
|
|
|
|
|
|
|
strokeWidth: 2.w,
|
|
|
|
|
|
|
|
dashPattern: [6, 3],
|
|
|
|
|
|
|
|
radius: Radius.circular(8.w),
|
|
|
|
|
|
|
|
child: Container(
|
|
|
|
|
|
|
|
width: widget.size ?? 160.w,
|
|
|
|
|
|
|
|
height: widget.size ?? 160.w,
|
|
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
Image.asset(
|
|
|
|
|
|
|
|
R.ASSETS_MANAGE_IC_IMAGE_PNG,
|
|
|
|
|
|
|
|
width: 60.w,
|
|
|
|
|
|
|
|
height: 60.w,
|
|
|
|
|
|
|
|
color: Color(0xFF999999),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
4.w.heightBox,
|
|
|
|
|
|
|
|
'上传图片'.text.color(kTextSubColor).size(22.sp).bold.make(),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
).material(color: Colors.transparent),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
).material(color: Colors.transparent),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
].sepWidget(separate: 10.w.widthBox),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Widget showImage(File file) {
|
|
|
|
|
|
|
|
return Stack(children: [
|
|
|
|
|
|
|
|
Container(
|
|
|
|
|
|
|
|
width: widget.size ?? 160.w,
|
|
|
|
|
|
|
|
height: widget.size ?? 160.w,
|
|
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
|
|
borderRadius: BorderRadius.circular(8.w), color: kBackgroundColor),
|
|
|
|
|
|
|
|
child: Image.file(file),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
Positioned(
|
|
|
|
|
|
|
|
top: 8.w,
|
|
|
|
|
|
|
|
right: 8.w,
|
|
|
|
|
|
|
|
child: Container(
|
|
|
|
|
|
|
|
width: 40.w,
|
|
|
|
|
|
|
|
height: 40.w,
|
|
|
|
|
|
|
|
child: Icon(
|
|
|
|
|
|
|
|
CupertinoIcons.xmark,
|
|
|
|
|
|
|
|
size: 20.w,
|
|
|
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
|
|
borderRadius: BorderRadius.circular(20.w),
|
|
|
|
|
|
|
|
color: Color(0xFF000000),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
).onTap(() {
|
|
|
|
|
|
|
|
_files.remove(file);
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|