flutterdartchat

Send audio message with Flyer Chat - Flutter


I'm currently creating an app where user can chat. I use Flyer Chat (flutter_chat_ui and firebase_chat_core).

I want to send audio message like iMessage, WhatsApp ..

In the app's chat, user can send Text, file and image. File and Image are taken from picker. So I could use this too and user just have to pick an audio file.

But I want to make it very easy for user, like a mic button in text field, when user tap it, record and then send.

I see some AudioMessageBuilder and audio message type but no idea how to use it.

Unfortunately the documentation does not talk about audio message.

How to use audio message with Flyer App ?


Solution

  • flutter_chat_ui doesn't provide Audio Message implementation out of the box. So you indeed have to implement the AudioMessageBuilder. You can use "Voicey" package for this - voice_message_package. Here is an example of implementation of the AudioMessageBuilder:

    audioMessageBuilder: (types.AudioMessage audioMessage,
                  {required int messageWidth}) {
                final isMine = audioMessage.author.id == _myUser.id;
                return VoiceMessageView(
                  backgroundColor: isMine ? primaryColor : secondaryColor,
                  controller: VoiceController(
                    audioSrc: audioMessage.uri,
                    maxDuration: audioMessage.duration,
                    onComplete: () {},
                    onPause: () {},
                    onPlaying: () {},
                    isFile: false,
                  ),
                );
              }