feat: Added selected image

This commit is contained in:
Deven Joshi
2020-11-09 14:21:32 +05:30
parent 38c06d5de7
commit 812f702845
+76 -21
View File
@@ -637,7 +637,7 @@ class MessageInputState extends State<MessageInput> {
Widget _buildPickerSection() {
switch (_filePickerIndex) {
case 0:
return FutureBuilder<List<Medium>>(
return FutureBuilder(
future: _getAllMedia(),
builder: (context, mediaData) {
if (!mediaData.hasData) {
@@ -647,40 +647,46 @@ class MessageInputState extends State<MessageInput> {
}
return GridView.builder(
itemCount: mediaData.data.length,
itemCount: mediaData.data.item2.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3),
itemBuilder: (context, position) {
return FutureBuilder<List<dynamic>>(
future: PhotoGallery.getThumbnail(
mediumId: mediaData.data[position].id),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 1.0, vertical: 1.0),
child: InkWell(
child: AspectRatio(
child: Stack(
children: [
AspectRatio(
aspectRatio: 1.0,
child: Image.memory(
snapshot.data,
fit: mediaData.data[position].height >
mediaData.data[position].width
mediaData.data.item2[position],
fit: mediaData.data.item1[position].height >
mediaData.data.item1[position].width
? BoxFit.fitWidth
: BoxFit.fitHeight,
),
aspectRatio: 1.0,
),
if (_attachments.any((element) =>
element.id ==
mediaData.data.item1[position].id))
Container(
color: Colors.black.withOpacity(0.5),
child: Center(
child: Icon(
StreamIcons.check_send,
color: Colors.white,
size: 24.0,
),
),
),
],
),
onTap: () {
_addAttachment(mediaData.data[position]);
_addAttachment(mediaData.data.item1[position]);
},
),
);
});
},
);
});
@@ -715,6 +721,7 @@ class MessageInputState extends State<MessageInput> {
localUri: file.path != null ? Uri.parse(file.path) : null,
type: medium.mediumType == MediumType.image ? 'image' : 'video',
),
id: medium.id,
);
setState(() {
@@ -747,10 +754,11 @@ class MessageInputState extends State<MessageInput> {
});
}
Future<List<Medium>> _getAllMedia() async {
Future<Tuple2<List<Medium>, List<dynamic>>> _getAllMedia() async {
var allAlbums = await PhotoGallery.listAlbums(mediumType: MediumType.image);
//var allVideoAlbums = await PhotoGallery.listAlbums(mediumType: MediumType.video);
List<Medium> resultList = [];
List<List<dynamic>> resultThumbnailList = [];
for (var album in allAlbums) {
var data = await album.listMedia();
@@ -764,7 +772,11 @@ class MessageInputState extends State<MessageInput> {
resultList.sort((a, b) => a.modifiedDate.compareTo(b.modifiedDate));
return resultList;
for (var e in resultList) {
resultThumbnailList.add(await PhotoGallery.getThumbnail(mediumId: e.id));
}
return Tuple2<List<Medium>, List<dynamic>>(resultList, resultThumbnailList);
}
OverlayEntry _buildMentionsOverlayEntry() {
@@ -1501,11 +1513,13 @@ class _SendingAttachment {
PlatformFile file;
Attachment attachment;
bool uploaded;
String id;
_SendingAttachment({
this.file,
this.attachment,
this.uploaded = false,
this.id,
});
}
@@ -1514,3 +1528,44 @@ extension StringExtension on String {
return "${this[0].toUpperCase()}${this.substring(1)}";
}
}
/// Represents a 2-tuple, or pair.
class Tuple2<T1, T2> {
/// Returns the first item of the tuple
final T1 item1;
/// Returns the second item of the tuple
final T2 item2;
/// Creates a new tuple value with the specified items.
const Tuple2(this.item1, this.item2);
/// Create a new tuple value with the specified list [items].
factory Tuple2.fromList(List items) {
if (items.length != 2) {
throw ArgumentError('items must have length 2');
}
return Tuple2<T1, T2>(items[0] as T1, items[1] as T2);
}
/// Returns a tuple with the first item set to the specified value.
Tuple2<T1, T2> withItem1(T1 v) => Tuple2<T1, T2>(v, item2);
/// Returns a tuple with the second item set to the specified value.
Tuple2<T1, T2> withItem2(T2 v) => Tuple2<T1, T2>(item1, v);
/// Creates a [List] containing the items of this [Tuple2].
///
/// The elements are in item order. The list is variable-length
/// if [growable] is true.
List toList({bool growable = false}) =>
List.from([item1, item2], growable: growable);
@override
String toString() => '[$item1, $item2]';
@override
bool operator ==(Object other) =>
other is Tuple2 && other.item1 == item1 && other.item2 == item2;
}