|
@@ -20,8 +20,9 @@ class ImageNineGrid extends StatefulWidget {
|
|
|
final double spacing; // 横向竖向的间距
|
|
|
final double borderRadius; //整体边框圆角
|
|
|
final Function(List<String>) onImagesChanged;
|
|
|
+ bool Function() beforePickImageCallback;
|
|
|
|
|
|
- const ImageNineGrid({
|
|
|
+ ImageNineGrid({
|
|
|
Key? key,
|
|
|
this.isSelectEnable = true,
|
|
|
this.maxImages = 9,
|
|
@@ -30,7 +31,9 @@ class ImageNineGrid extends StatefulWidget {
|
|
|
this.borderRadius = 5.0,
|
|
|
required this.initialImages,
|
|
|
required this.onImagesChanged,
|
|
|
- }) : super(key: key);
|
|
|
+ bool Function()? beforePickImageCallback, // 修改构造函数
|
|
|
+ }) : beforePickImageCallback = beforePickImageCallback ?? (() => true), // 设置默认值
|
|
|
+ super(key: key);
|
|
|
|
|
|
@override
|
|
|
_ImageNineGridState createState() => _ImageNineGridState();
|
|
@@ -55,6 +58,10 @@ class _ImageNineGridState extends State<ImageNineGrid> {
|
|
|
|
|
|
// 选择图片
|
|
|
Future<void> _pickImage() async {
|
|
|
+ if (mounted) {
|
|
|
+ // 隐藏键盘
|
|
|
+ FocusScope.of(context).unfocus();
|
|
|
+ }
|
|
|
ImagePickerUtils().show(context, (filePath) {
|
|
|
if (Utils.isNotEmpty(filePath)) {
|
|
|
setState(() {
|
|
@@ -113,7 +120,13 @@ class _ImageNineGridState extends State<ImageNineGrid> {
|
|
|
if (widget.isSelectEnable && _images.length < widget.maxImages) {
|
|
|
gridChildren.add(
|
|
|
GestureDetector(
|
|
|
- onTap: _pickImage,
|
|
|
+ onTap: () {
|
|
|
+ final bool res = widget.beforePickImageCallback.call();
|
|
|
+ if (!res) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ _pickImage();
|
|
|
+ },
|
|
|
child: Container(
|
|
|
decoration: BoxDecoration(
|
|
|
color: context.appColors.imgGrayBg,
|