|
|
|
@@ -139,26 +139,34 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
child: const Text(label_select_image_from_library), |
|
|
|
onPressed: () async { |
|
|
|
Navigator.pop(context, 'Discard'); |
|
|
|
FilePickerResult result = |
|
|
|
await FilePicker.platform.pickFiles(type: FileType.image); |
|
|
|
|
|
|
|
FilePickerResult result = await FilePicker.platform |
|
|
|
.pickFiles(type: FileType.image, allowMultiple: true); |
|
|
|
if (result != null) { |
|
|
|
UtilAction.compressImage(File(result.files.single.path)) |
|
|
|
.then((compressFile) async { |
|
|
|
var lengthFileInBytes = await compressFile.length(); |
|
|
|
if (lengthFileInBytes > ConstCommon.kFileSize) { |
|
|
|
Utils.showSnackBarWarning(message: label_file_to_large); |
|
|
|
} else { |
|
|
|
Media newMedia = Media() |
|
|
|
..isVideo = false |
|
|
|
..isServerFile = false |
|
|
|
..pathFile = compressFile.path; |
|
|
|
currentItems.add(newMedia); |
|
|
|
addNewFilePaths.add(compressFile.path); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(addNewFilePaths, deleteFilePaths); |
|
|
|
var listFuture = List<Future<File>>(); |
|
|
|
result.files.forEach((element) { |
|
|
|
listFuture.add(UtilAction.compressImage(File(element.path))); |
|
|
|
}); |
|
|
|
Future.wait(listFuture).then((values) { |
|
|
|
bool isExistedFileTooLarge = false; |
|
|
|
values.forEach((compressFile) { |
|
|
|
if (compressFile.lengthSync() > ConstCommon.kFileSize) { |
|
|
|
isExistedFileTooLarge = true; |
|
|
|
} else { |
|
|
|
Media newMedia = Media() |
|
|
|
..isVideo = false |
|
|
|
..isServerFile = false |
|
|
|
..pathFile = compressFile.path; |
|
|
|
currentItems.add(newMedia); |
|
|
|
addNewFilePaths.add(compressFile.path); |
|
|
|
} |
|
|
|
}); |
|
|
|
if (isExistedFileTooLarge) { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: "Tập tin có kích thước lớn đã được loại bỏ."); |
|
|
|
} |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(addNewFilePaths, deleteFilePaths); |
|
|
|
}); |
|
|
|
} |
|
|
|
}), |
|
|
|
@@ -166,25 +174,30 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
child: const Text(label_select_video_from_library), |
|
|
|
onPressed: () async { |
|
|
|
Navigator.pop(context, 'Discard'); |
|
|
|
FilePickerResult result = |
|
|
|
await FilePicker.platform.pickFiles(type: FileType.video); |
|
|
|
FilePickerResult result = await FilePicker.platform |
|
|
|
.pickFiles(type: FileType.video, allowMultiple: true); |
|
|
|
|
|
|
|
if (result != null) { |
|
|
|
String filePath = result.files.single.path; |
|
|
|
var lengthFileInBytes = result.files.single.size * 1000; |
|
|
|
if (lengthFileInBytes > ConstCommon.kFileSize) { |
|
|
|
Utils.showSnackBarWarning(message: label_file_to_large); |
|
|
|
} else { |
|
|
|
Media newMedia = Media() |
|
|
|
..isVideo = true |
|
|
|
..isServerFile = false |
|
|
|
..pathFile = filePath; |
|
|
|
currentItems.add(newMedia); |
|
|
|
addNewFilePaths.add(filePath); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(addNewFilePaths, deleteFilePaths); |
|
|
|
bool isExistedFileTooLarge = false; |
|
|
|
result.files?.forEach((videoFile) { |
|
|
|
if (videoFile.size * 1000 > ConstCommon.kFileSize) { |
|
|
|
isExistedFileTooLarge = true; |
|
|
|
} else { |
|
|
|
Media newMedia = Media() |
|
|
|
..isVideo = true |
|
|
|
..isServerFile = false |
|
|
|
..pathFile = videoFile.path; |
|
|
|
currentItems.add(newMedia); |
|
|
|
addNewFilePaths.add(videoFile.path); |
|
|
|
} |
|
|
|
}); |
|
|
|
if (isExistedFileTooLarge) { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: "Tập tin có kích thước lớn đã được loại bỏ."); |
|
|
|
} |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(addNewFilePaths, deleteFilePaths); |
|
|
|
} |
|
|
|
}), |
|
|
|
CupertinoDialogAction( |