|
|
|
@@ -19,8 +19,7 @@ import 'hoz_list_view.dart'; |
|
|
|
|
|
|
|
class WidgetMediaPicker extends StatefulWidget { |
|
|
|
final List<Media> currentItems; |
|
|
|
final Function(List<String> addNewFilePaths, List<String> deleteFilePaths) |
|
|
|
onChangeFiles; |
|
|
|
final Function(List<String> addNewFilePaths, List<String> deleteFilePaths) onChangeFiles; |
|
|
|
WidgetMediaPicker({this.currentItems, @required this.onChangeFiles}); |
|
|
|
@override |
|
|
|
_WidgetMediaPickerState createState() => _WidgetMediaPickerState(); |
|
|
|
@@ -39,10 +38,8 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return BlocProvider<MediaHelperBloc>( |
|
|
|
create: (BuildContext contextA) => |
|
|
|
MediaHelperBloc()..add(ChangeListMedia(items: currentItems)), |
|
|
|
child: BlocBuilder<MediaHelperBloc, MediaHelperState>( |
|
|
|
builder: (contextB, state) { |
|
|
|
create: (BuildContext contextA) => MediaHelperBloc()..add(ChangeListMedia(items: currentItems)), |
|
|
|
child: BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (contextB, state) { |
|
|
|
if (state is MediaHelperFailure) { |
|
|
|
return Container(); |
|
|
|
} else if (state is MediaHelperSuccess) { |
|
|
|
@@ -52,8 +49,7 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: <Widget>[ |
|
|
|
Text('Hình ảnh/ Video', |
|
|
|
style: TextStyle(color: Colors.black54, fontSize: 16)), |
|
|
|
Text('Hình ảnh/ Video', style: TextStyle(color: Colors.black54, fontSize: 16)), |
|
|
|
SizedBox( |
|
|
|
height: 8, |
|
|
|
), |
|
|
|
@@ -96,12 +92,10 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
title: Text(label_title_select_media), |
|
|
|
actions: <Widget>[ |
|
|
|
CupertinoDialogAction( |
|
|
|
child: const Text(label_take_photo_or_video), |
|
|
|
child: const Text('Chụp ảnh'), |
|
|
|
onPressed: () { |
|
|
|
Navigator.pop(context, 'Discard'); |
|
|
|
Navigator.of(context) |
|
|
|
.push(MaterialPageRoute(builder: (context) => CameraHelper())) |
|
|
|
.then((value) { |
|
|
|
Navigator.of(context).push(MaterialPageRoute(builder: (context) => CameraHelper())).then((value) { |
|
|
|
if (value != null) { |
|
|
|
print("ok"); |
|
|
|
print(value); |
|
|
|
@@ -118,8 +112,7 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
..pathFile = filePath; |
|
|
|
currentItems.add(newMedia); |
|
|
|
addNewFilePaths.add(filePath); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
..add(ChangeListMedia(items: currentItems)); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context)..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(addNewFilePaths, deleteFilePaths); |
|
|
|
} |
|
|
|
}); |
|
|
|
@@ -127,11 +120,10 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
}); |
|
|
|
}), |
|
|
|
CupertinoDialogAction( |
|
|
|
child: const Text(label_select_image_from_library), |
|
|
|
child: const Text('Chọn ảnh'), |
|
|
|
onPressed: () async { |
|
|
|
Navigator.pop(context, 'Discard'); |
|
|
|
FilePickerResult result = await FilePicker.platform |
|
|
|
.pickFiles(type: FileType.image, allowMultiple: true); |
|
|
|
FilePickerResult result = await FilePicker.platform.pickFiles(type: FileType.image, allowMultiple: true); |
|
|
|
if (result != null) { |
|
|
|
var listFuture = List<Future<File>>(); |
|
|
|
result.files.forEach((element) { |
|
|
|
@@ -152,45 +144,43 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
} |
|
|
|
}); |
|
|
|
if (isExistedFileTooLarge) { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: "Tập tin có kích thước lớn đã được loại bỏ."); |
|
|
|
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)); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context)..add(ChangeListMedia(items: currentItems)); |
|
|
|
widget.onChangeFiles(addNewFilePaths, deleteFilePaths); |
|
|
|
}); |
|
|
|
} |
|
|
|
}), |
|
|
|
CupertinoDialogAction( |
|
|
|
child: const Text(label_select_video_from_library), |
|
|
|
onPressed: () async { |
|
|
|
Navigator.pop(context, 'Discard'); |
|
|
|
FilePickerResult result = await FilePicker.platform |
|
|
|
.pickFiles(type: FileType.video, allowMultiple: true); |
|
|
|
// CupertinoDialogAction( |
|
|
|
// child: const Text(label_select_video_from_library), |
|
|
|
// onPressed: () async { |
|
|
|
// Navigator.pop(context, 'Discard'); |
|
|
|
// FilePickerResult result = await FilePicker.platform |
|
|
|
// .pickFiles(type: FileType.video, allowMultiple: true); |
|
|
|
|
|
|
|
if (result != null) { |
|
|
|
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); |
|
|
|
} |
|
|
|
}), |
|
|
|
// if (result != null) { |
|
|
|
// 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( |
|
|
|
child: const Text(label_cancel), |
|
|
|
textStyle: TextStyle(fontWeight: FontWeight.bold), |
|
|
|
@@ -203,8 +193,7 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
} |
|
|
|
|
|
|
|
_buildListPoster() { |
|
|
|
return BlocBuilder<MediaHelperBloc, MediaHelperState>( |
|
|
|
builder: (context, state) { |
|
|
|
return BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (context, state) { |
|
|
|
if (state is MediaHelperSuccess) { |
|
|
|
return WrapContentHozListView( |
|
|
|
list: currentItems, |
|
|
|
@@ -217,15 +206,13 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { |
|
|
|
item: item, |
|
|
|
deleteImage: (item) { |
|
|
|
if (item.isServerFile) { |
|
|
|
var url = item.pathFile |
|
|
|
.replaceAll(ConstCommon.baseImageUrl, ''); |
|
|
|
var url = item.pathFile.replaceAll(ConstCommon.baseImageUrl, ''); |
|
|
|
deleteFilePaths.add(url); |
|
|
|
} |
|
|
|
addNewFilePaths.remove(item.pathFile); |
|
|
|
currentItems.remove(item); |
|
|
|
widget.onChangeFiles(addNewFilePaths, deleteFilePaths); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
.add(ChangeListMedia(items: currentItems)); |
|
|
|
BlocProvider.of<MediaHelperBloc>(context).add(ChangeListMedia(items: currentItems)); |
|
|
|
}), |
|
|
|
); |
|
|
|
}); |
|
|
|
@@ -265,15 +252,9 @@ class _WidgetItemMedia extends StatelessWidget { |
|
|
|
: Container( |
|
|
|
margin: EdgeInsets.all(4.0), |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: Colors.white, |
|
|
|
border: Border.all(color: Colors.grey), |
|
|
|
borderRadius: |
|
|
|
BorderRadius.all(Radius.circular(8.0))), |
|
|
|
color: Colors.white, border: Border.all(color: Colors.grey), borderRadius: BorderRadius.all(Radius.circular(8.0))), |
|
|
|
child: item.isServerFile |
|
|
|
? CachedNetworkImage( |
|
|
|
placeholder: (context, url) => |
|
|
|
Icon(Icons.crop_original), |
|
|
|
imageUrl: item.pathFile) |
|
|
|
? CachedNetworkImage(placeholder: (context, url) => Icon(Icons.crop_original), imageUrl: item.pathFile) |
|
|
|
: Image.file(File(item.pathFile)), |
|
|
|
)), |
|
|
|
Positioned.fill( |