|
|
|
|
@ -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,7 +17,8 @@ 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;
|
|
|
|
|
@ -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,
|
|
|
|
|
@ -60,8 +60,8 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
onPressed: (widget.enabled == false)
|
|
|
|
|
? () {}
|
|
|
|
|
: widget.showAsGrid
|
|
|
|
|
? showFileSourceSheet
|
|
|
|
|
: onFilePicker),
|
|
|
|
|
? showFileSourceSheet
|
|
|
|
|
: onFilePicker),
|
|
|
|
|
16.height,
|
|
|
|
|
],
|
|
|
|
|
if (widget.files.isNotEmpty)
|
|
|
|
|
@ -101,6 +101,9 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
if (result != null) {
|
|
|
|
|
for (var path in result.paths) {
|
|
|
|
|
widget.files.add(File(path!));
|
|
|
|
|
if (widget.onChange != null) {
|
|
|
|
|
widget.onChange!(widget.files);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
@ -112,7 +115,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImageSource source = (await showModalBottomSheet(
|
|
|
|
|
ImageSource? source = (await showModalBottomSheet(
|
|
|
|
|
context: context,
|
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.vertical(
|
|
|
|
|
@ -143,8 +146,8 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
12.height,
|
|
|
|
|
],
|
|
|
|
|
).paddingAll(21),
|
|
|
|
|
)) as ImageSource;
|
|
|
|
|
|
|
|
|
|
)) as ImageSource?;
|
|
|
|
|
if (source == null) return;
|
|
|
|
|
final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800);
|
|
|
|
|
|
|
|
|
|
if (pickedFile != null) {
|
|
|
|
|
@ -154,7 +157,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
widget.onChange!(widget.files);
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget gridItem(IconData iconData, String title) {
|
|
|
|
|
@ -187,28 +190,26 @@ 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,
|
|
|
|
|
children: [
|
|
|
|
|
icon.toSvgAsset(),
|
|
|
|
|
24.height,
|
|
|
|
|
label.bodyText2(context).custom(color: AppColor.black20),
|
|
|
|
|
],
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
icon.toSvgAsset(),
|
|
|
|
|
24.height,
|
|
|
|
|
label.bodyText2(context).custom(color: AppColor.black20),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Row(
|
|
|
|
|
@ -216,7 +217,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
listCard(
|
|
|
|
|
icon: 'camera_icon',
|
|
|
|
|
label: '${context.translation.open}\n${context.translation.camera}',
|
|
|
|
|
label: '${context.translation.open}\n${context.translation.camera}',
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.of(context).pop(ImageSource.camera);
|
|
|
|
|
},
|
|
|
|
|
@ -230,7 +231,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
),
|
|
|
|
|
listCard(
|
|
|
|
|
icon: 'file_icon',
|
|
|
|
|
label: '${context.translation.open}\n${context.translation.files}',
|
|
|
|
|
label: '${context.translation.open}\n${context.translation.files}',
|
|
|
|
|
onTap: () async {
|
|
|
|
|
await fromFilePicker();
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
@ -286,36 +287,32 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AttachmentModel {
|
|
|
|
|
int id = 0;
|
|
|
|
|
File? file;
|
|
|
|
|
|
|
|
|
|
AttachmentModel(this.id, this.file);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AttachmentModel {
|
|
|
|
|
int id =0;
|
|
|
|
|
File ? file;
|
|
|
|
|
AttachmentModel(this.id,this.file);
|
|
|
|
|
|
|
|
|
|
factory AttachmentModel.fromJson(Map<String, dynamic> json) {
|
|
|
|
|
return AttachmentModel(
|
|
|
|
|
json['id'] ?? 0,
|
|
|
|
|
json['file'] != null ? File(json['file']) : null,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
|
return {
|
|
|
|
|
'id': id,
|
|
|
|
|
'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;
|
|
|
|
|
@ -325,16 +322,16 @@ class AttachmentPicker extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
AttachmentPicker(
|
|
|
|
|
{Key? key,
|
|
|
|
|
this.attachment = const <AttachmentModel>[],
|
|
|
|
|
required this.label,
|
|
|
|
|
this.error = false,
|
|
|
|
|
this.buttonHeight,
|
|
|
|
|
this.buttonIcon,
|
|
|
|
|
this.enabled = true,
|
|
|
|
|
this.onlyImages = false,
|
|
|
|
|
this.onChange,
|
|
|
|
|
this.showAsGrid = false,
|
|
|
|
|
this.buttonColor})
|
|
|
|
|
this.attachment = const <AttachmentModel>[],
|
|
|
|
|
required this.label,
|
|
|
|
|
this.error = false,
|
|
|
|
|
this.buttonHeight,
|
|
|
|
|
this.buttonIcon,
|
|
|
|
|
this.enabled = true,
|
|
|
|
|
this.onlyImages = false,
|
|
|
|
|
this.onChange,
|
|
|
|
|
this.showAsGrid = false,
|
|
|
|
|
this.buttonColor})
|
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
@ -355,15 +352,15 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
|
onPressed: (widget.enabled == false)
|
|
|
|
|
? () {}
|
|
|
|
|
: widget.showAsGrid
|
|
|
|
|
? showFileSourceSheet
|
|
|
|
|
: onFilePicker),
|
|
|
|
|
? showFileSourceSheet
|
|
|
|
|
: onFilePicker),
|
|
|
|
|
16.height,
|
|
|
|
|
if (widget.attachment.isNotEmpty)
|
|
|
|
|
Wrap(
|
|
|
|
|
spacing: 8.toScreenWidth,
|
|
|
|
|
children: List.generate(
|
|
|
|
|
widget.attachment.length,
|
|
|
|
|
(index) {
|
|
|
|
|
(index) {
|
|
|
|
|
File image = widget.attachment[index].file!;
|
|
|
|
|
return MultiFilesPickerItem(
|
|
|
|
|
file: image,
|
|
|
|
|
@ -481,16 +478,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 +497,7 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Row(
|
|
|
|
|
@ -510,7 +505,7 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
listCard(
|
|
|
|
|
icon: 'camera_icon',
|
|
|
|
|
label: '${context.translation.open}\n${context.translation.camera}',
|
|
|
|
|
label: '${context.translation.open}\n${context.translation.camera}',
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.of(context).pop(ImageSource.camera);
|
|
|
|
|
},
|
|
|
|
|
@ -524,7 +519,7 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
|
),
|
|
|
|
|
listCard(
|
|
|
|
|
icon: 'file_icon',
|
|
|
|
|
label: '${context.translation.open}\n${context.translation.files}',
|
|
|
|
|
label: '${context.translation.open}\n${context.translation.files}',
|
|
|
|
|
onTap: () async {
|
|
|
|
|
await fromFilePicker();
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
@ -572,7 +567,7 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
|
widget.onChange!(widget.attachment);
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
|