|
|
|
@ -1,7 +1,6 @@
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
@ -18,12 +17,13 @@ class MultiFilesPicker extends StatefulWidget {
|
|
|
|
final String label;
|
|
|
|
final String label;
|
|
|
|
final bool error;
|
|
|
|
final bool error;
|
|
|
|
final List<File> files;
|
|
|
|
final List<File> files;
|
|
|
|
final List<AttachmentModel> attachment ;
|
|
|
|
final List<AttachmentModel> attachment;
|
|
|
|
|
|
|
|
|
|
|
|
final bool enabled, onlyImages;
|
|
|
|
final bool enabled, onlyImages;
|
|
|
|
double? buttonHeight;
|
|
|
|
double? buttonHeight;
|
|
|
|
Widget? buttonIcon;
|
|
|
|
Widget? buttonIcon;
|
|
|
|
Color? buttonColor;
|
|
|
|
Color? buttonColor;
|
|
|
|
final Function(List<File>)? onChange;
|
|
|
|
final VoidCallback? onChange;
|
|
|
|
final bool showAsGrid;
|
|
|
|
final bool showAsGrid;
|
|
|
|
|
|
|
|
|
|
|
|
MultiFilesPicker(
|
|
|
|
MultiFilesPicker(
|
|
|
|
@ -51,7 +51,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
return Column(
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
if(widget.enabled)...[
|
|
|
|
if (widget.enabled) ...[
|
|
|
|
AppDashedButton(
|
|
|
|
AppDashedButton(
|
|
|
|
title: widget.label,
|
|
|
|
title: widget.label,
|
|
|
|
height: widget.buttonHeight,
|
|
|
|
height: widget.buttonHeight,
|
|
|
|
@ -60,8 +60,8 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
onPressed: (widget.enabled == false)
|
|
|
|
onPressed: (widget.enabled == false)
|
|
|
|
? () {}
|
|
|
|
? () {}
|
|
|
|
: widget.showAsGrid
|
|
|
|
: widget.showAsGrid
|
|
|
|
? showFileSourceSheet
|
|
|
|
? showFileSourceSheet
|
|
|
|
: onFilePicker),
|
|
|
|
: onFilePicker),
|
|
|
|
16.height,
|
|
|
|
16.height,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
if (widget.files.isNotEmpty)
|
|
|
|
if (widget.files.isNotEmpty)
|
|
|
|
@ -80,7 +80,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
widget.files.remove(image);
|
|
|
|
widget.files.remove(image);
|
|
|
|
if (widget.onChange != null) {
|
|
|
|
if (widget.onChange != null) {
|
|
|
|
widget.onChange!(widget.files);
|
|
|
|
widget.onChange!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setState(() {});
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
@ -101,6 +101,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
if (result != null) {
|
|
|
|
if (result != null) {
|
|
|
|
for (var path in result.paths) {
|
|
|
|
for (var path in result.paths) {
|
|
|
|
widget.files.add(File(path!));
|
|
|
|
widget.files.add(File(path!));
|
|
|
|
|
|
|
|
widget.onChange!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setState(() {});
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -151,10 +152,10 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
File fileImage = File(pickedFile.path);
|
|
|
|
File fileImage = File(pickedFile.path);
|
|
|
|
widget.files.add(fileImage);
|
|
|
|
widget.files.add(fileImage);
|
|
|
|
if (widget.onChange != null) {
|
|
|
|
if (widget.onChange != null) {
|
|
|
|
widget.onChange!(widget.files);
|
|
|
|
widget.onChange!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setState(() {});
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Widget gridItem(IconData iconData, String title) {
|
|
|
|
Widget gridItem(IconData iconData, String title) {
|
|
|
|
@ -187,28 +188,26 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
ImageSource? source = await showModalBottomSheet<ImageSource>(
|
|
|
|
ImageSource? source = await showModalBottomSheet<ImageSource>(
|
|
|
|
context: context,
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext 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(
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: onTap,
|
|
|
|
onTap: onTap,
|
|
|
|
child: Container(
|
|
|
|
child: Container(
|
|
|
|
constraints: BoxConstraints(minWidth: 111.toScreenWidth,minHeight: 111.toScreenHeight),
|
|
|
|
constraints: BoxConstraints(minWidth: 111.toScreenWidth, minHeight: 111.toScreenHeight),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth,vertical: 12.toScreenHeight),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth, vertical: 12.toScreenHeight),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), border: Border.all(width: 1, color: AppColor.white70)),
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
|
|
|
border: Border.all(width: 1,color:AppColor.white70)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
child: Column(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
icon.toSvgAsset(),
|
|
|
|
icon.toSvgAsset(),
|
|
|
|
24.height,
|
|
|
|
24.height,
|
|
|
|
label.bodyText2(context).custom(color: AppColor.black20),
|
|
|
|
label.bodyText2(context).custom(color: AppColor.black20),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
return Container(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Row(
|
|
|
|
child: Row(
|
|
|
|
@ -216,7 +215,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
children: <Widget>[
|
|
|
|
children: <Widget>[
|
|
|
|
listCard(
|
|
|
|
listCard(
|
|
|
|
icon: 'camera_icon',
|
|
|
|
icon: 'camera_icon',
|
|
|
|
label: '${context.translation.open}\n${context.translation.camera}',
|
|
|
|
label: '${context.translation.open}\n${context.translation.camera}',
|
|
|
|
onTap: () {
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop(ImageSource.camera);
|
|
|
|
Navigator.of(context).pop(ImageSource.camera);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
@ -230,7 +229,7 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
listCard(
|
|
|
|
listCard(
|
|
|
|
icon: 'file_icon',
|
|
|
|
icon: 'file_icon',
|
|
|
|
label: '${context.translation.open}\n${context.translation.files}',
|
|
|
|
label: '${context.translation.open}\n${context.translation.files}',
|
|
|
|
onTap: () async {
|
|
|
|
onTap: () async {
|
|
|
|
await fromFilePicker();
|
|
|
|
await fromFilePicker();
|
|
|
|
Navigator.pop(context);
|
|
|
|
Navigator.pop(context);
|
|
|
|
@ -273,49 +272,41 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
|
|
|
|
|
|
|
|
|
|
|
|
if (pickedFile != null) {
|
|
|
|
if (pickedFile != null) {
|
|
|
|
File fileImage = File(pickedFile.path);
|
|
|
|
File fileImage = File(pickedFile.path);
|
|
|
|
if (fileImage != null) {
|
|
|
|
widget.files.add(fileImage);
|
|
|
|
widget.files.add(fileImage);
|
|
|
|
if (widget.onChange != null) {
|
|
|
|
if (widget.onChange != null) {
|
|
|
|
widget.onChange!();
|
|
|
|
widget.onChange!(widget.files);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
factory AttachmentModel.fromJson(Map<String, dynamic> json) {
|
|
|
|
return AttachmentModel(
|
|
|
|
return AttachmentModel(
|
|
|
|
json['id'] ?? 0,
|
|
|
|
json['id'] ?? 0,
|
|
|
|
json['file'] != null ? File(json['file']) : null,
|
|
|
|
json['file'] != null ? File(json['file']) : null,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
'id': id,
|
|
|
|
'id': id,
|
|
|
|
'file': file?.path,
|
|
|
|
'file': file?.path,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class AttachmentPicker extends StatefulWidget {
|
|
|
|
class AttachmentPicker extends StatefulWidget {
|
|
|
|
final String label;
|
|
|
|
final String label;
|
|
|
|
final bool error;
|
|
|
|
final bool error;
|
|
|
|
final List<AttachmentModel> attachment ;
|
|
|
|
final List<AttachmentModel> attachment;
|
|
|
|
|
|
|
|
|
|
|
|
final bool enabled, onlyImages;
|
|
|
|
final bool enabled, onlyImages;
|
|
|
|
double? buttonHeight;
|
|
|
|
double? buttonHeight;
|
|
|
|
Widget? buttonIcon;
|
|
|
|
Widget? buttonIcon;
|
|
|
|
@ -325,16 +316,16 @@ class AttachmentPicker extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
|
|
AttachmentPicker(
|
|
|
|
AttachmentPicker(
|
|
|
|
{Key? key,
|
|
|
|
{Key? key,
|
|
|
|
this.attachment = const <AttachmentModel>[],
|
|
|
|
this.attachment = const <AttachmentModel>[],
|
|
|
|
required this.label,
|
|
|
|
required this.label,
|
|
|
|
this.error = false,
|
|
|
|
this.error = false,
|
|
|
|
this.buttonHeight,
|
|
|
|
this.buttonHeight,
|
|
|
|
this.buttonIcon,
|
|
|
|
this.buttonIcon,
|
|
|
|
this.enabled = true,
|
|
|
|
this.enabled = true,
|
|
|
|
this.onlyImages = false,
|
|
|
|
this.onlyImages = false,
|
|
|
|
this.onChange,
|
|
|
|
this.onChange,
|
|
|
|
this.showAsGrid = false,
|
|
|
|
this.showAsGrid = false,
|
|
|
|
this.buttonColor})
|
|
|
|
this.buttonColor})
|
|
|
|
: super(key: key);
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
@ -355,15 +346,15 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
onPressed: (widget.enabled == false)
|
|
|
|
onPressed: (widget.enabled == false)
|
|
|
|
? () {}
|
|
|
|
? () {}
|
|
|
|
: widget.showAsGrid
|
|
|
|
: widget.showAsGrid
|
|
|
|
? showFileSourceSheet
|
|
|
|
? showFileSourceSheet
|
|
|
|
: onFilePicker),
|
|
|
|
: onFilePicker),
|
|
|
|
16.height,
|
|
|
|
16.height,
|
|
|
|
if (widget.attachment.isNotEmpty)
|
|
|
|
if (widget.attachment.isNotEmpty)
|
|
|
|
Wrap(
|
|
|
|
Wrap(
|
|
|
|
spacing: 8.toScreenWidth,
|
|
|
|
spacing: 8.toScreenWidth,
|
|
|
|
children: List.generate(
|
|
|
|
children: List.generate(
|
|
|
|
widget.attachment.length,
|
|
|
|
widget.attachment.length,
|
|
|
|
(index) {
|
|
|
|
(index) {
|
|
|
|
File image = widget.attachment[index].file!;
|
|
|
|
File image = widget.attachment[index].file!;
|
|
|
|
return MultiFilesPickerItem(
|
|
|
|
return MultiFilesPickerItem(
|
|
|
|
file: image,
|
|
|
|
file: image,
|
|
|
|
@ -481,16 +472,13 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
ImageSource? source = await showModalBottomSheet<ImageSource>(
|
|
|
|
ImageSource? source = await showModalBottomSheet<ImageSource>(
|
|
|
|
context: context,
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext 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(
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: onTap,
|
|
|
|
onTap: onTap,
|
|
|
|
child: Container(
|
|
|
|
child: Container(
|
|
|
|
constraints: BoxConstraints(minWidth: 111.toScreenWidth,minHeight: 111.toScreenHeight),
|
|
|
|
constraints: BoxConstraints(minWidth: 111.toScreenWidth, minHeight: 111.toScreenHeight),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth,vertical: 12.toScreenHeight),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth, vertical: 12.toScreenHeight),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), border: Border.all(width: 1, color: AppColor.white70)),
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
|
|
|
border: Border.all(width: 1,color:AppColor.white70)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
child: Column(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
@ -503,6 +491,7 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
return Container(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Row(
|
|
|
|
child: Row(
|
|
|
|
@ -510,7 +499,7 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
children: <Widget>[
|
|
|
|
children: <Widget>[
|
|
|
|
listCard(
|
|
|
|
listCard(
|
|
|
|
icon: 'camera_icon',
|
|
|
|
icon: 'camera_icon',
|
|
|
|
label: '${context.translation.open}\n${context.translation.camera}',
|
|
|
|
label: '${context.translation.open}\n${context.translation.camera}',
|
|
|
|
onTap: () {
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop(ImageSource.camera);
|
|
|
|
Navigator.of(context).pop(ImageSource.camera);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
@ -524,7 +513,7 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
listCard(
|
|
|
|
listCard(
|
|
|
|
icon: 'file_icon',
|
|
|
|
icon: 'file_icon',
|
|
|
|
label: '${context.translation.open}\n${context.translation.files}',
|
|
|
|
label: '${context.translation.open}\n${context.translation.files}',
|
|
|
|
onTap: () async {
|
|
|
|
onTap: () async {
|
|
|
|
await fromFilePicker();
|
|
|
|
await fromFilePicker();
|
|
|
|
Navigator.pop(context);
|
|
|
|
Navigator.pop(context);
|
|
|
|
@ -572,7 +561,7 @@ class _AttachmentPickerState extends State<AttachmentPicker> {
|
|
|
|
widget.onChange!(widget.attachment);
|
|
|
|
widget.onChange!(widget.attachment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setState(() {});
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|