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:typed_data';
import 'package:audio_waveforms/audio_waveforms.dart';
import 'package:flutter/foundation.dart';
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.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<String, dynamic> 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<String, dynamic> toJson() => {
"userChatHistoryId": userChatHistoryId == null ? null : userChatHistoryId,

@ -1102,7 +1102,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<void> 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;

@ -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,

Loading…
Cancel
Save