|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
import 'package:flutter/cupertino.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
|
|
|
import 'package:get/get.dart'; |
|
|
|
|
|
|
|
|
import 'bloc/media_helper_bloc.dart'; |
|
|
import 'bloc/media_helper_bloc.dart'; |
|
|
import 'hoz_list_view.dart'; |
|
|
import 'hoz_list_view.dart'; |
|
|
|
|
|
|
|
|
return BlocBuilder<MediaHelperBloc, MediaHelperState>( |
|
|
return BlocBuilder<MediaHelperBloc, MediaHelperState>( |
|
|
builder: (context, state) { |
|
|
builder: (context, state) { |
|
|
if (state is MediaHelperSuccess) { |
|
|
if (state is MediaHelperSuccess) { |
|
|
return WrapContentHozListView( |
|
|
|
|
|
itemBuilder: (context, index) { |
|
|
|
|
|
var item = currentItems[index]; |
|
|
|
|
|
return _WidgetItemMedia( |
|
|
|
|
|
item: item, |
|
|
|
|
|
deleteImage: (item) { |
|
|
|
|
|
if (item.isServerFile) { |
|
|
|
|
|
var url = |
|
|
|
|
|
item.pathFile.replaceAll(ConstCommon.baseImageUrl, ''); |
|
|
|
|
|
deleteFilePaths.add(url); |
|
|
|
|
|
} |
|
|
|
|
|
currentItems.remove(item); |
|
|
|
|
|
widget.onChangeFiles(addNewFilePaths, deleteFilePaths); |
|
|
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
|
|
.add(ChangeListMedia(items: currentItems)); |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
separatorBuilder: (context, index) { |
|
|
|
|
|
return SizedBox(width: 4); |
|
|
|
|
|
}, |
|
|
|
|
|
list: currentItems, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
return GridView.count( |
|
|
|
|
|
physics: NeverScrollableScrollPhysics(), |
|
|
|
|
|
shrinkWrap: true, |
|
|
|
|
|
crossAxisCount: 4, |
|
|
|
|
|
children: currentItems.map( |
|
|
|
|
|
(item) { |
|
|
|
|
|
return _WidgetItemMedia( |
|
|
|
|
|
item: item, |
|
|
|
|
|
deleteImage: (item) { |
|
|
|
|
|
if (item.isServerFile) { |
|
|
|
|
|
var url = item.pathFile |
|
|
|
|
|
.replaceAll(ConstCommon.baseImageUrl, ''); |
|
|
|
|
|
deleteFilePaths.add(url); |
|
|
|
|
|
} |
|
|
|
|
|
currentItems.remove(item); |
|
|
|
|
|
widget.onChangeFiles(addNewFilePaths, deleteFilePaths); |
|
|
|
|
|
BlocProvider.of<MediaHelperBloc>(context) |
|
|
|
|
|
.add(ChangeListMedia(items: currentItems)); |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
).toList()); |
|
|
} |
|
|
} |
|
|
return Container(); |
|
|
return Container(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
_WidgetItemMedia({@required this.item, @required this.deleteImage}); |
|
|
_WidgetItemMedia({@required this.item, @required this.deleteImage}); |
|
|
|
|
|
|
|
|
BuildContext _context; |
|
|
BuildContext _context; |
|
|
|
|
|
// screenSize/rowGridview - iconSize - (rowGridview-1)*marginContainer |
|
|
|
|
|
// Get.width/4 - 24 - 3*4 |
|
|
|
|
|
double positionIconDelete = -(Get.width / 4 - 36); |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
Widget build(BuildContext context) { |
|
|
Widget build(BuildContext context) { |
|
|
|
|
|
|
|
|
print("Show preview image or video"); |
|
|
print("Show preview image or video"); |
|
|
}, |
|
|
}, |
|
|
child: Stack( |
|
|
child: Stack( |
|
|
alignment: Alignment.bottomCenter, |
|
|
|
|
|
|
|
|
alignment: Alignment.topRight, |
|
|
overflow: Overflow.visible, |
|
|
overflow: Overflow.visible, |
|
|
children: <Widget>[ |
|
|
children: <Widget>[ |
|
|
Positioned( |
|
|
|
|
|
|
|
|
Positioned.fill( |
|
|
child: item.isVideo |
|
|
child: item.isVideo |
|
|
? VideoWidget( |
|
|
? VideoWidget( |
|
|
pathFile: item.pathFile, |
|
|
pathFile: item.pathFile, |
|
|
|
|
|
|
|
|
play: false, |
|
|
play: false, |
|
|
) |
|
|
) |
|
|
: Container( |
|
|
: Container( |
|
|
width: 100, |
|
|
|
|
|
height: 100, |
|
|
|
|
|
|
|
|
margin: EdgeInsets.all(4.0), |
|
|
decoration: BoxDecoration( |
|
|
decoration: BoxDecoration( |
|
|
color: Colors.white, |
|
|
color: Colors.white, |
|
|
border: Border.all(color: Colors.grey), |
|
|
border: Border.all(color: Colors.grey), |
|
|
|
|
|
|
|
|
placeholder: (context, url) => |
|
|
placeholder: (context, url) => |
|
|
Icon(Icons.crop_original), |
|
|
Icon(Icons.crop_original), |
|
|
imageUrl: item.pathFile) |
|
|
imageUrl: item.pathFile) |
|
|
: Image.file(File(item.pathFile), |
|
|
|
|
|
width: 100, height: 100), |
|
|
|
|
|
|
|
|
: Image.file(File(item.pathFile)), |
|
|
)), |
|
|
)), |
|
|
Positioned( |
|
|
|
|
|
top: -14, |
|
|
|
|
|
right: -14, |
|
|
|
|
|
|
|
|
Positioned.fill( |
|
|
|
|
|
top: positionIconDelete, |
|
|
|
|
|
right: positionIconDelete, |
|
|
child: IconButton( |
|
|
child: IconButton( |
|
|
icon: Icon( |
|
|
icon: Icon( |
|
|
Icons.cancel, |
|
|
Icons.cancel, |