|
|
|
@ -194,8 +194,35 @@ class _MowadhafhiHRRequestState extends State<MowadhafhiHRRequest> {
|
|
|
|
SimpleButton(LocaleKeys.add.tr(), () async {
|
|
|
|
SimpleButton(LocaleKeys.add.tr(), () async {
|
|
|
|
FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: true);
|
|
|
|
FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: true);
|
|
|
|
if (result != null) {
|
|
|
|
if (result != null) {
|
|
|
|
attachmentFiles = attachmentFiles + result.paths.map((path) => File(path!)).toList();
|
|
|
|
// Maximum file size: 2 MB (in bytes)
|
|
|
|
|
|
|
|
const int maxFileSizeInBytes = 2 * 1024 * 1024; // 2 MB
|
|
|
|
|
|
|
|
List<File> newFiles = [];
|
|
|
|
|
|
|
|
List<String> oversizedFiles = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String? path in result.paths) {
|
|
|
|
|
|
|
|
if (path != null) {
|
|
|
|
|
|
|
|
File file = File(path);
|
|
|
|
|
|
|
|
int fileSize = await file.length();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fileSize <= maxFileSizeInBytes) {
|
|
|
|
|
|
|
|
newFiles.add(file);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String fileName = path.split('/').last;
|
|
|
|
|
|
|
|
oversizedFiles.add(fileName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (newFiles.isNotEmpty) {
|
|
|
|
|
|
|
|
attachmentFiles = attachmentFiles + newFiles;
|
|
|
|
attachmentFiles = attachmentFiles.toSet().toList();
|
|
|
|
attachmentFiles = attachmentFiles.toSet().toList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (oversizedFiles.isNotEmpty) {
|
|
|
|
|
|
|
|
// String fileList = oversizedFiles.join(', ');
|
|
|
|
|
|
|
|
Utils.showToast('File exceeds 2 MB limit');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, fontSize: 14),
|
|
|
|
}, fontSize: 14),
|
|
|
|
|