chat voice message implementation

merge-requests/116/head
Aamir Muhammad 3 years ago
parent 12defa65ac
commit 47a697f352

@ -1,6 +1,7 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:audio_waveforms/audio_waveforms.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
List<SingleUserChatModel> singleUserChatModelFromJson(String str) => List<SingleUserChatModel>.from(json.decode(str).map((x) => SingleUserChatModel.fromJson(x))); List<SingleUserChatModel> singleUserChatModelFromJson(String str) => List<SingleUserChatModel>.from(json.decode(str).map((x) => SingleUserChatModel.fromJson(x)));
@ -33,7 +34,8 @@ class SingleUserChatModel {
this.isReplied, this.isReplied,
this.isImageLoaded, this.isImageLoaded,
this.image, this.image,
this.voice}); this.voice,
this.voiceController});
int? userChatHistoryId; int? userChatHistoryId;
int? userChatHistoryLineId; int? userChatHistoryLineId;
@ -60,6 +62,7 @@ class SingleUserChatModel {
bool? isImageLoaded; bool? isImageLoaded;
Uint8List? image; Uint8List? image;
Uint8List? voice; Uint8List? voice;
PlayerController? voiceController;
factory SingleUserChatModel.fromJson(Map<String, dynamic> json) => SingleUserChatModel( factory SingleUserChatModel.fromJson(Map<String, dynamic> json) => SingleUserChatModel(
userChatHistoryId: json["userChatHistoryId"] == null ? null : json["userChatHistoryId"], userChatHistoryId: json["userChatHistoryId"] == null ? null : json["userChatHistoryId"],
@ -86,7 +89,8 @@ class SingleUserChatModel {
isReplied: false, isReplied: false,
isImageLoaded: false, isImageLoaded: false,
image: null, image: null,
voice: null); voice: null,
voiceController: json["fileTypeId"] == 13 ? PlayerController() : null);
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
"userChatHistoryId": userChatHistoryId == null ? null : userChatHistoryId, "userChatHistoryId": userChatHistoryId == null ? null : userChatHistoryId,

@ -1102,7 +1102,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<void> deleteRecoding() async { Future<void> deleteRecoding() async {
_recodeDuration = 0; _recodeDuration = 0;
_timer?.cancel(); _timer?.cancel();
recorderController.stop(true); if (path == null) {
path = await recorderController.stop(true);
} else {
await recorderController.stop(true);
}
if (path != null && path!.isNotEmpty) { if (path != null && path!.isNotEmpty) {
File delFile = File(path!); File delFile = File(path!);
double fileSizeInKB = delFile.lengthSync() / 1024; double fileSizeInKB = delFile.lengthSync() / 1024;

@ -117,7 +117,7 @@ class ChatBubble extends StatelessWidget {
), ),
).paddingOnly(bottom: 4), ).paddingOnly(bottom: 4),
if (fileTypeID == 13) if (fileTypeID == 13)
currentWaveBubble(context).onPress(() { currentWaveBubble(context, cItem).onPress(() {
data.playVoice(context, data: cItem); data.playVoice(context, data: cItem);
}) })
else else
@ -220,7 +220,7 @@ class ChatBubble extends StatelessWidget {
), ),
).paddingOnly(bottom: 4), ).paddingOnly(bottom: 4),
if (fileTypeID == 13) if (fileTypeID == 13)
recipetWaveBubble(context).onPress(() { recipetWaveBubble(context, cItem).onPress(() {
data.playVoice(context, data: cItem); data.playVoice(context, data: cItem);
}) })
else else
@ -288,7 +288,8 @@ class ChatBubble extends StatelessWidget {
} }
} }
Widget currentWaveBubble(BuildContext context) { Widget currentWaveBubble(BuildContext context, SingleUserChatModel data) {
PlayerController cunController = PlayerController();
return Container( return Container(
margin: const EdgeInsets.all(0), margin: const EdgeInsets.all(0),
decoration: BoxDecoration( decoration: BoxDecoration(
@ -315,7 +316,7 @@ class ChatBubble extends StatelessWidget {
).paddingAll(10), ).paddingAll(10),
AudioFileWaveforms( AudioFileWaveforms(
size: Size(MediaQuery.of(context).size.width * 0.3, 10), size: Size(MediaQuery.of(context).size.width * 0.3, 10),
playerController: data.playerController, playerController: data.voiceController!,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
margin: EdgeInsets.zero, margin: EdgeInsets.zero,
enableSeekGesture: true, enableSeekGesture: true,
@ -336,7 +337,8 @@ class ChatBubble extends StatelessWidget {
).circle(5); ).circle(5);
} }
Widget recipetWaveBubble(BuildContext context) { Widget recipetWaveBubble(BuildContext context, SingleUserChatModel data) {
PlayerController repController = PlayerController();
return Container( return Container(
margin: const EdgeInsets.all(0), margin: const EdgeInsets.all(0),
decoration: BoxDecoration( decoration: BoxDecoration(
@ -363,7 +365,7 @@ class ChatBubble extends StatelessWidget {
).paddingAll(10), ).paddingAll(10),
AudioFileWaveforms( AudioFileWaveforms(
size: Size(MediaQuery.of(context).size.width * 0.3, 10), size: Size(MediaQuery.of(context).size.width * 0.3, 10),
playerController: data.playerController, playerController: data.voiceController!,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
margin: EdgeInsets.zero, margin: EdgeInsets.zero,
enableSeekGesture: true, enableSeekGesture: true,

Loading…
Cancel
Save