From 47a697f352e4452729d15628399eaa5afaf56615 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Thu, 22 Dec 2022 11:13:26 +0300 Subject: [PATCH] chat voice message implementation --- .../chat/get_single_user_chat_list_model.dart | 8 ++++++-- lib/provider/chat_provider_model.dart | 6 +++++- lib/ui/chat/chat_bubble.dart | 14 ++++++++------ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/models/chat/get_single_user_chat_list_model.dart b/lib/models/chat/get_single_user_chat_list_model.dart index c585af7..7ca60a8 100644 --- a/lib/models/chat/get_single_user_chat_list_model.dart +++ b/lib/models/chat/get_single_user_chat_list_model.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'dart:typed_data'; +import 'package:audio_waveforms/audio_waveforms.dart'; import 'package:flutter/foundation.dart'; List singleUserChatModelFromJson(String str) => List.from(json.decode(str).map((x) => SingleUserChatModel.fromJson(x))); @@ -33,7 +34,8 @@ class SingleUserChatModel { this.isReplied, this.isImageLoaded, this.image, - this.voice}); + this.voice, + this.voiceController}); int? userChatHistoryId; int? userChatHistoryLineId; @@ -60,6 +62,7 @@ class SingleUserChatModel { bool? isImageLoaded; Uint8List? image; Uint8List? voice; + PlayerController? voiceController; factory SingleUserChatModel.fromJson(Map json) => SingleUserChatModel( userChatHistoryId: json["userChatHistoryId"] == null ? null : json["userChatHistoryId"], @@ -86,7 +89,8 @@ class SingleUserChatModel { isReplied: false, isImageLoaded: false, image: null, - voice: null); + voice: null, + voiceController: json["fileTypeId"] == 13 ? PlayerController() : null); Map toJson() => { "userChatHistoryId": userChatHistoryId == null ? null : userChatHistoryId, diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index 16bf327..5f7bf0e 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -1102,7 +1102,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { Future deleteRecoding() async { _recodeDuration = 0; _timer?.cancel(); - recorderController.stop(true); + if (path == null) { + path = await recorderController.stop(true); + } else { + await recorderController.stop(true); + } if (path != null && path!.isNotEmpty) { File delFile = File(path!); double fileSizeInKB = delFile.lengthSync() / 1024; diff --git a/lib/ui/chat/chat_bubble.dart b/lib/ui/chat/chat_bubble.dart index bb67365..9f0396a 100644 --- a/lib/ui/chat/chat_bubble.dart +++ b/lib/ui/chat/chat_bubble.dart @@ -117,7 +117,7 @@ class ChatBubble extends StatelessWidget { ), ).paddingOnly(bottom: 4), if (fileTypeID == 13) - currentWaveBubble(context).onPress(() { + currentWaveBubble(context, cItem).onPress(() { data.playVoice(context, data: cItem); }) else @@ -220,7 +220,7 @@ class ChatBubble extends StatelessWidget { ), ).paddingOnly(bottom: 4), if (fileTypeID == 13) - recipetWaveBubble(context).onPress(() { + recipetWaveBubble(context, cItem).onPress(() { data.playVoice(context, data: cItem); }) else @@ -288,7 +288,8 @@ class ChatBubble extends StatelessWidget { } } - Widget currentWaveBubble(BuildContext context) { + Widget currentWaveBubble(BuildContext context, SingleUserChatModel data) { + PlayerController cunController = PlayerController(); return Container( margin: const EdgeInsets.all(0), decoration: BoxDecoration( @@ -315,7 +316,7 @@ class ChatBubble extends StatelessWidget { ).paddingAll(10), AudioFileWaveforms( size: Size(MediaQuery.of(context).size.width * 0.3, 10), - playerController: data.playerController, + playerController: data.voiceController!, padding: EdgeInsets.zero, margin: EdgeInsets.zero, enableSeekGesture: true, @@ -336,7 +337,8 @@ class ChatBubble extends StatelessWidget { ).circle(5); } - Widget recipetWaveBubble(BuildContext context) { + Widget recipetWaveBubble(BuildContext context, SingleUserChatModel data) { + PlayerController repController = PlayerController(); return Container( margin: const EdgeInsets.all(0), decoration: BoxDecoration( @@ -363,7 +365,7 @@ class ChatBubble extends StatelessWidget { ).paddingAll(10), AudioFileWaveforms( size: Size(MediaQuery.of(context).size.width * 0.3, 10), - playerController: data.playerController, + playerController: data.voiceController!, padding: EdgeInsets.zero, margin: EdgeInsets.zero, enableSeekGesture: true,