|
|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
|
@ -18,12 +17,13 @@ class MultiFilesPicker extends StatefulWidget {
|
|
|
|
|
final String label;
|
|
|
|
|
final bool error;
|
|
|
|
|
final List<File> files;
|
|
|
|
|
final List<AttachmentModel> attachment ;
|
|
|
|
|
final List<AttachmentModel> attachment;
|
|
|
|
|
|
|
|
|
|
final bool enabled, onlyImages;
|
|
|
|
|
double? buttonHeight;
|
|
|
|
|
Widget? buttonIcon;
|
|
|
|
|
Color? buttonColor;
|
|
|
|
|
final Function(List<File>)? onChange;
|
|
|
|
|
final VoidCallback? onChange;
|
|
|
|
|
final bool showAsGrid;
|
|
|
|
|
|
|
|
|
|
MultiFilesPicker(
|
|
|
|
|
@ -51,7 +51,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
return Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
if(widget.enabled)...[
|
|
|
|
|
if (widget.enabled) ...[
|
|
|
|
|
AppDashedButton(
|
|
|
|
|
title: widget.label,
|
|
|
|
|
height: widget.buttonHeight,
|
|
|
|
|
@ -80,7 +80,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
}
|
|
|
|
|
widget.files.remove(image);
|
|
|
|
|
if (widget.onChange != null) {
|
|
|
|
|
widget.onChange!(widget.files);
|
|
|
|
|
widget.onChange!();
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
@ -101,6 +101,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
if (result != null) {
|
|
|
|
|
for (var path in result.paths) {
|
|
|
|
|
widget.files.add(File(path!));
|
|
|
|
|
widget.onChange!();
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
@ -151,7 +152,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
File fileImage = File(pickedFile.path);
|
|
|
|
|
widget.files.add(fileImage);
|
|
|
|
|
if (widget.onChange != null) {
|
|
|
|
|
widget.onChange!(widget.files);
|
|
|
|
|
widget.onChange!();
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
@ -187,16 +188,13 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
ImageSource? source = await showModalBottomSheet<ImageSource>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
Widget listCard({required String icon, required String label, required VoidCallback onTap}){
|
|
|
|
|
Widget listCard({required String icon, required String label, required VoidCallback onTap}) {
|
|
|
|
|
return GestureDetector(
|
|
|
|
|
onTap: onTap,
|
|
|
|
|
child: Container(
|
|
|
|
|
constraints: BoxConstraints(minWidth: 111.toScreenWidth,minHeight: 111.toScreenHeight),
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth,vertical: 12.toScreenHeight),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
border: Border.all(width: 1,color:AppColor.white70)
|
|
|
|
|
),
|
|
|
|
|
constraints: BoxConstraints(minWidth: 111.toScreenWidth, minHeight: 111.toScreenHeight),
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth, vertical: 12.toScreenHeight),
|
|
|
|
|
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), border: Border.all(width: 1, color: AppColor.white70)),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
@ -209,6 +207,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Row(
|
|
|
|
|
@ -273,27 +272,20 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
|
|
|
|
|
if (pickedFile != null) {
|
|
|
|
|
File fileImage = File(pickedFile.path);
|
|
|
|
|
if (fileImage != null) {
|
|
|
|
|
widget.files.add(fileImage);
|
|
|
|
|
if (widget.onChange != null) {
|
|
|
|
|
widget.onChange!(widget.files);
|
|
|
|
|
widget.onChange!();
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AttachmentModel {
|
|
|
|
|
int id =0;
|
|
|
|
|
File ? file;
|
|
|
|
|
AttachmentModel(this.id,this.file);
|
|
|
|
|
int id = 0;
|
|
|
|
|
File? file;
|
|
|
|
|
|
|
|
|
|
AttachmentModel(this.id, this.file);
|
|
|
|
|
|
|
|
|
|
factory AttachmentModel.fromJson(Map<String, dynamic> json) {
|
|
|
|
|
return AttachmentModel(
|
|
|
|
|
@ -308,14 +300,13 @@ class AttachmentModel {
|
|
|
|
|
'file': file?.path,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AttachmentPicker extends StatefulWidget {
|
|
|
|
|
final String label;
|
|
|
|
|
final bool error;
|
|
|
|
|
final List<AttachmentModel> attachment ;
|
|
|
|
|
final List<AttachmentModel> attachment;
|
|
|
|
|
|
|
|
|
|
final bool enabled, onlyImages;
|
|
|
|
|
double? buttonHeight;
|
|
|
|
|
Widget? buttonIcon;
|
|
|
|
|
@ -481,16 +472,13 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
|
ImageSource? source = await showModalBottomSheet<ImageSource>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
Widget listCard({required String icon, required String label, required VoidCallback onTap}){
|
|
|
|
|
Widget listCard({required String icon, required String label, required VoidCallback onTap}) {
|
|
|
|
|
return GestureDetector(
|
|
|
|
|
onTap: onTap,
|
|
|
|
|
child: Container(
|
|
|
|
|
constraints: BoxConstraints(minWidth: 111.toScreenWidth,minHeight: 111.toScreenHeight),
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth,vertical: 12.toScreenHeight),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
border: Border.all(width: 1,color:AppColor.white70)
|
|
|
|
|
),
|
|
|
|
|
constraints: BoxConstraints(minWidth: 111.toScreenWidth, minHeight: 111.toScreenHeight),
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth, vertical: 12.toScreenHeight),
|
|
|
|
|
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), border: Border.all(width: 1, color: AppColor.white70)),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
@ -503,6 +491,7 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Row(
|
|
|
|
|
|