|
|
|
@@ -2,17 +2,15 @@ import 'dart:io'; |
|
|
|
|
|
|
|
import 'package:farm_tpf/custom_model/Media.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/camera_helper.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/shimmer_image.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/widget_show_video.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_color.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_common.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_string.dart'; |
|
|
|
import 'package:file_picker/file_picker.dart'; |
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
|
import 'package:get/route_manager.dart'; |
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
|
import 'package:thumbnails/thumbnails.dart'; |
|
|
|
import 'package:video_player/video_player.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
|
|
|
|
import 'bloc/media_helper_bloc.dart'; |
|
|
|
import 'hoz_list_view.dart'; |
|
|
|
@@ -83,7 +81,7 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
)), |
|
|
|
), |
|
|
|
SizedBox( |
|
|
|
height: 4.0, |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
Container( |
|
|
|
height: 150, |
|
|
|
@@ -110,16 +108,27 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
if (value != null) { |
|
|
|
print("ok"); |
|
|
|
print(value); |
|
|
|
String filePath = value; |
|
|
|
Media newMedia = Media() |
|
|
|
..isVideo = false |
|
|
|
..isServerFile = false |
|
|
|
..pathFile = filePath; |
|
|
|
currentItems.add(newMedia); |
|
|
|
files.add(filePath); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(files); |
|
|
|
String filePath = value[0]; |
|
|
|
File f = File(filePath); |
|
|
|
f.length().then((lengthFileInBytes) { |
|
|
|
if (lengthFileInBytes > ConstCommon.kFileSize) { |
|
|
|
Get.snackbar(label_file_to_large, |
|
|
|
"Kích thước: $lengthFileInBytes bytes", |
|
|
|
snackPosition: SnackPosition.BOTTOM); |
|
|
|
} else { |
|
|
|
bool isVideo = value[1]; |
|
|
|
Media newMedia = Media() |
|
|
|
..isVideo = isVideo |
|
|
|
..isServerFile = false |
|
|
|
..pathFile = filePath; |
|
|
|
currentItems.add(newMedia); |
|
|
|
files.add(filePath); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(files); |
|
|
|
} |
|
|
|
print("Kích thước: $lengthFileInBytes bytes"); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}), |
|
|
|
@@ -132,15 +141,23 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
|
|
|
|
if (result != null) { |
|
|
|
String filePath = result.files.single.path; |
|
|
|
Media newMedia = Media() |
|
|
|
..isVideo = false |
|
|
|
..isServerFile = false |
|
|
|
..pathFile = filePath; |
|
|
|
currentItems.add(newMedia); |
|
|
|
files.add(filePath); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(files); |
|
|
|
var lengthFileInBytes = result.files.single.size * 1000; |
|
|
|
if (lengthFileInBytes > ConstCommon.kFileSize) { |
|
|
|
Get.snackbar(label_file_to_large, |
|
|
|
"Kích thước: $lengthFileInBytes bytes", |
|
|
|
snackPosition: SnackPosition.BOTTOM); |
|
|
|
} else { |
|
|
|
Media newMedia = Media() |
|
|
|
..isVideo = false |
|
|
|
..isServerFile = false |
|
|
|
..pathFile = filePath; |
|
|
|
currentItems.add(newMedia); |
|
|
|
files.add(filePath); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(files); |
|
|
|
} |
|
|
|
print("file size: $lengthFileInBytes"); |
|
|
|
} |
|
|
|
}), |
|
|
|
CupertinoDialogAction( |
|
|
|
@@ -151,25 +168,24 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
await FilePicker.platform.pickFiles(type: FileType.video); |
|
|
|
|
|
|
|
if (result != null) { |
|
|
|
//Get thumb video |
|
|
|
var appDocDir = await getApplicationDocumentsDirectory(); |
|
|
|
final folderPath = appDocDir.path; |
|
|
|
String filePath = await Thumbnails.getThumbnail( |
|
|
|
thumbnailFolder: folderPath, |
|
|
|
videoFile: result.files.single.path, |
|
|
|
imageType: ThumbFormat |
|
|
|
.PNG, //this image will store in created folderpath |
|
|
|
quality: 30); |
|
|
|
|
|
|
|
Media newMedia = Media() |
|
|
|
..isVideo = false |
|
|
|
..isServerFile = false |
|
|
|
..pathFile = filePath; |
|
|
|
currentItems.add(newMedia); |
|
|
|
files.add(filePath); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(files); |
|
|
|
String filePath = result.files.single.path; |
|
|
|
var lengthFileInBytes = result.files.single.size * 1000; |
|
|
|
if (lengthFileInBytes > ConstCommon.kFileSize) { |
|
|
|
Get.snackbar(label_file_to_large, |
|
|
|
"Kích thước: $lengthFileInBytes bytes", |
|
|
|
snackPosition: SnackPosition.BOTTOM); |
|
|
|
} else { |
|
|
|
Media newMedia = Media() |
|
|
|
..isVideo = true |
|
|
|
..isServerFile = false |
|
|
|
..pathFile = filePath; |
|
|
|
currentItems.add(newMedia); |
|
|
|
files.add(filePath); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(files); |
|
|
|
} |
|
|
|
print("file size: $lengthFileInBytes"); |
|
|
|
} |
|
|
|
}), |
|
|
|
CupertinoDialogAction( |
|
|
|
@@ -201,7 +217,7 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
}); |
|
|
|
}, |
|
|
|
separatorBuilder: (context, index) { |
|
|
|
return SizedBox(width: 14); |
|
|
|
return SizedBox(width: 4); |
|
|
|
}, |
|
|
|
list: state.items, |
|
|
|
); |
|
|
|
@@ -222,9 +238,6 @@ class _WidgetItemMedia extends StatelessWidget { |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
_context = context; |
|
|
|
VideoPlayerController _controller = |
|
|
|
VideoPlayerController.file(File(item.pathFile)); |
|
|
|
_controller.play(); |
|
|
|
return GestureDetector( |
|
|
|
onTap: () { |
|
|
|
print("Show preview image or video"); |
|
|
|
@@ -234,17 +247,30 @@ class _WidgetItemMedia extends StatelessWidget { |
|
|
|
overflow: Overflow.visible, |
|
|
|
children: <Widget>[ |
|
|
|
Positioned( |
|
|
|
child: ClipRRect( |
|
|
|
borderRadius: BorderRadius.circular(8), |
|
|
|
child: Image.file(File(item.pathFile), width: 100, height: 100), |
|
|
|
)), |
|
|
|
child: item.isVideo |
|
|
|
? VideoWidget( |
|
|
|
pathFile: item.pathFile, |
|
|
|
play: false, |
|
|
|
) |
|
|
|
: Container( |
|
|
|
width: 100, |
|
|
|
height: 100, |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: Colors.white, |
|
|
|
border: Border.all(color: Colors.grey), |
|
|
|
borderRadius: |
|
|
|
BorderRadius.all(Radius.circular(8.0))), |
|
|
|
child: Image.file(File(item.pathFile), |
|
|
|
width: 100, height: 100), |
|
|
|
)), |
|
|
|
Positioned( |
|
|
|
top: -5, |
|
|
|
right: -5, |
|
|
|
top: -14, |
|
|
|
right: -14, |
|
|
|
child: IconButton( |
|
|
|
icon: Icon( |
|
|
|
Icons.cancel, |
|
|
|
color: Colors.redAccent, |
|
|
|
size: 24, |
|
|
|
), |
|
|
|
onPressed: () { |
|
|
|
print("On tap delete media"); |