Browse Source

select multi image, video

master
daivph 5 years ago
parent
commit
c222faab51
2 changed files with 47 additions and 36 deletions
  1. +0
    -2
      android/app/src/main/AndroidManifest.xml
  2. +47
    -34
      lib/presentation/custom_widgets/widget_media_picker.dart

+ 0
- 2
android/app/src/main/AndroidManifest.xml View File

@@ -5,8 +5,6 @@
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA" />
<application

+ 47
- 34
lib/presentation/custom_widgets/widget_media_picker.dart View File

@@ -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(

Loading…
Cancel
Save