[Bug] - strange behavior with video messages
Closed this issue · 5 comments
As you can see in the attached video, when i'm sending 2 videos one after another it behave's strangely, it doesn't happen with photos and regular text
WhatsApp.Video.2022-09-16.at.13.26.04.mp4
update!
i was able to reproduce the bug in the example project
as you can see in the attached video
Screen.Recording.2022-09-17.at.21.34.43.mov
the following is the add video button
`
[
IconButton(
icon: Icon(Icons.attach_file),
onPressed: () async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
allowedExtensions: [
'jpg',
'png',
'jpeg',
'mov',
'mp4',
],
allowMultiple: true,
allowCompression: true,
withData: true,
withReadStream: true,
type: FileType.custom,
);
if (result != null) {
List<ChatMessage> newMessages = result.files.map((file) {
return ChatMessage(
user: user,
text: file.name,
medias: [
ChatMedia(
fileName: file.name,
type:
file.extension == 'mov' || file.extension == 'mp4'
? MediaType.video
: MediaType.image,
url: file.path!,
),
],
createdAt: DateTime.now(),
);
}).toList();
setState(() {
messages.insertAll(0, newMessages);
});
}
},
),
]
`
update! i was able to reproduce the bug in the example project as you can see in the attached video
Screen.Recording.2022-09-17.at.21.34.43.mov
the following is the add video button` [ IconButton( icon: Icon(Icons.attach_file), onPressed: () async { FilePickerResult? result = await FilePicker.platform.pickFiles( allowedExtensions: [ 'jpg', 'png', 'jpeg', 'mov', 'mp4', ], allowMultiple: true, allowCompression: true, withData: true, withReadStream: true, type: FileType.custom, );
if (result != null) { List<ChatMessage> newMessages = result.files.map((file) { return ChatMessage( user: user, text: file.name, medias: [ ChatMedia( fileName: file.name, type: file.extension == 'mov' || file.extension == 'mp4' ? MediaType.video : MediaType.image, url: file.path!, ), ], createdAt: DateTime.now(), ); }).toList(); setState(() { messages.insertAll(0, newMessages); }); } }, ), ]
`
Can you give me the full code of media.dart that you're using please?
Ok
(BTW, huge thanks for this incredible package)
import 'package:dash_chat_2/dash_chat_2.dart';
import 'package:examples/data.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
class Media extends StatefulWidget {
@override
_MediaState createState() => _MediaState();
}
class _MediaState extends State<Media> {
List<ChatMessage> messages = media;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Media example'),
),
body: DashChat(
currentUser: user,
inputOptions: InputOptions(
leading: [
IconButton(
icon: Icon(Icons.camera_alt),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.attach_file),
onPressed: () async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
allowedExtensions: [
'jpg',
'png',
'jpeg',
'mov',
'mp4',
],
allowMultiple: true,
allowCompression: true,
withData: true,
withReadStream: true,
type: FileType.custom,
);
if (result != null) {
List<ChatMessage> newMessages = result.files.map((file) {
return ChatMessage(
user: user,
text: file.name,
medias: [
ChatMedia(
fileName: file.name,
type:
file.extension == 'mov' || file.extension == 'mp4'
? MediaType.video
: MediaType.image,
url: file.path!,
),
],
createdAt: DateTime.now(),
);
}).toList();
setState(() {
messages.insertAll(0, newMessages);
});
}
},
),
],
sendOnEnter: true,
),
onSend: (ChatMessage m) {
setState(() {
messages.insert(0, m);
});
},
messages: messages,
),
);
}
}
I was able to reproduce it and it should be fixed, I'll publish a new version