|
|
|
@ -8,10 +8,11 @@ import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
|
import 'package:aku_community_manager/const/resource.dart';
|
|
|
|
|
import 'package:velocity_x/velocity_x.dart';
|
|
|
|
|
import 'package:aku_community_manager/utils/extension/list_extension.dart';
|
|
|
|
|
|
|
|
|
|
class AkuPickImageWidget extends StatefulWidget {
|
|
|
|
|
final double size;
|
|
|
|
|
final Function(File file) onChanged;
|
|
|
|
|
final Function(List<File> files) onChanged;
|
|
|
|
|
AkuPickImageWidget({Key key, this.size, this.onChanged}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@ -19,44 +20,20 @@ class AkuPickImageWidget extends StatefulWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AkuPickImageWidgetState extends State<AkuPickImageWidget> {
|
|
|
|
|
File _file;
|
|
|
|
|
List<File> _files = [];
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return _file != null
|
|
|
|
|
? 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(() {
|
|
|
|
|
_file = null;
|
|
|
|
|
setState(() {});
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
])
|
|
|
|
|
: GestureDetector(
|
|
|
|
|
return Row(
|
|
|
|
|
children: [
|
|
|
|
|
..._files?.map((e) => showImage(e))?.toList(),
|
|
|
|
|
GestureDetector(
|
|
|
|
|
onTap: () async {
|
|
|
|
|
await akuPickImage().then((value) => _file = File(value.path));
|
|
|
|
|
widget.onChanged(_file);
|
|
|
|
|
await akuPickImage().then(
|
|
|
|
|
(value) => _files.add(
|
|
|
|
|
File(value.path),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
widget.onChanged(_files);
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
child: DottedBorder(
|
|
|
|
@ -84,6 +61,40 @@ class _AkuPickImageWidgetState extends State<AkuPickImageWidget> {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
).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(() {});
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|