chat voice message implementation

merge-requests/116/head
Aamir Muhammad 3 years ago
parent 97dd82aff7
commit 5eec9dc07b

@ -32,6 +32,7 @@ import 'package:uuid/uuid.dart';
class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
ScrollController scrollController = ScrollController(); ScrollController scrollController = ScrollController();
TextEditingController message = TextEditingController(); TextEditingController message = TextEditingController();
TextEditingController search = TextEditingController(); TextEditingController search = TextEditingController();
List<SingleUserChatModel> userChatHistory = []; List<SingleUserChatModel> userChatHistory = [];
@ -1180,7 +1181,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
chatReplyId: null, chatReplyId: null,
isAttachment: true, isAttachment: true,
isReply: isMsgReply, isReply: isMsgReply,
voicFile: voiceFile, voiceFile: voiceFile,
); );
notifyListeners(); notifyListeners();
} }
@ -1198,7 +1199,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
bool? isReply, bool? isReply,
bool? isAttachment, bool? isAttachment,
int? chatReplyId, int? chatReplyId,
File? voicFile}) async { File? voiceFile}) async {
Uuid uuid = const Uuid(); Uuid uuid = const Uuid();
String contentNo = uuid.v4(); String contentNo = uuid.v4();
String msg = msgText!; String msg = msgText!;
@ -1219,10 +1220,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
fileTypeResponse: isAttachment! fileTypeResponse: isAttachment!
? FileTypeResponse( ? FileTypeResponse(
fileTypeId: fileTypeId, fileTypeId: fileTypeId,
fileTypeName: getFileExtension(voicFile!.path).toString(), fileTypeName: getFileExtension(voiceFile!.path).toString(),
fileKind: "file", fileKind: "file",
fileName: msgText, fileName: msgText,
fileTypeDescription: getFileTypeDescription(getFileExtension(voicFile!.path).toString()), fileTypeDescription: getFileTypeDescription(getFileExtension(voiceFile!.path).toString()),
) )
: null, : null,
image: null, image: null,
@ -1293,7 +1294,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
file.readAsBytesSync(); file.readAsBytesSync();
Utils.hideLoading(context); Utils.hideLoading(context);
await data.voiceController!.preparePlayer(file.path, 1.0); await data.voiceController!.preparePlayer(file.path, 1.0);
data.voiceController!.startPlayer(finishMode: FinishMode.pause); data.voiceController!.startPlayer(finishMode: FinishMode.stop);
notifyListeners(); notifyListeners();
} catch (e) { } catch (e) {
Utils.showToast("Cannot open file."); Utils.showToast("Cannot open file.");
@ -1301,7 +1302,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
void stopPlaying(BuildContext context, {required SingleUserChatModel data}) async { void stopPlaying(BuildContext context, {required SingleUserChatModel data}) async {
await data.voiceController!.pausePlayer(); await data.voiceController!.stopPlayer();
notifyListeners(); notifyListeners();
} }
@ -1316,9 +1317,24 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
return file.path; return file.path;
} }
// data.scrollController.animateTo( void scrollToMsg(SingleUserChatModel data) {
// data.scrollController.position.maxScrollExtent, if (data.userChatReplyResponse != null && data.userChatReplyResponse!.userChatHistoryId != null) {
// duration: const Duration(milliseconds: 100), int index = userChatHistory.indexWhere((SingleUserChatModel element) => element.userChatHistoryId == data.userChatReplyResponse!.userChatHistoryId);
// curve: Curves.easeOut, double contentSize = scrollController.position.viewportDimension + scrollController.position.maxScrollExtent;
// ); double target = contentSize * index / userChatHistory.length;
scrollController.position.animateTo(
target,
duration: const Duration(seconds: 1),
curve: Curves.easeInOut,
);
// scrollController.scrollTo(index: 150, duration: Duration(seconds: 1));
// scrollController.animateTo(offset, duration: duration, curve: curve);
}
// scrollController.animateTo(
// scrollController.position.maxScrollExtent,
// duration: const Duration(milliseconds: 100),
// curve: Curves.easeOut,
// );
}
} }

@ -100,7 +100,9 @@ class ChatBubble extends StatelessWidget {
], ],
), ),
), ),
).paddingOnly(bottom: 7).onPress(() {}), ).paddingOnly(bottom: 7).onPress(() {
data.scrollToMsg(cItem);
}),
if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3)
ClipRRect( ClipRRect(
borderRadius: BorderRadius.circular(5.0), borderRadius: BorderRadius.circular(5.0),
@ -118,9 +120,9 @@ class ChatBubble extends StatelessWidget {
).paddingOnly(bottom: 4), ).paddingOnly(bottom: 4),
if (fileTypeID == 13) if (fileTypeID == 13)
currentWaveBubble(context, cItem).onPress(() { currentWaveBubble(context, cItem).onPress(() {
if(cItem.voiceController!.playerState == PlayerState.playing){ if (cItem.voiceController!.playerState == PlayerState.playing) {
data.stopPlaying(context, data: cItem); data.stopPlaying(context, data: cItem);
}else{ } else {
data.playVoice(context, data: cItem); data.playVoice(context, data: cItem);
} }
}) })
@ -208,6 +210,7 @@ class ChatBubble extends StatelessWidget {
), ),
), ),
).paddingOnly(bottom: 7).onPress(() { ).paddingOnly(bottom: 7).onPress(() {
data.scrollToMsg(cItem);
}), }),
if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3)
ClipRRect( ClipRRect(
@ -226,12 +229,11 @@ class ChatBubble extends StatelessWidget {
).paddingOnly(bottom: 4), ).paddingOnly(bottom: 4),
if (fileTypeID == 13) if (fileTypeID == 13)
recipetWaveBubble(context, cItem).onPress(() { recipetWaveBubble(context, cItem).onPress(() {
if(cItem.voiceController!.playerState == PlayerState.playing){ if (cItem.voiceController!.playerState == PlayerState.playing) {
data.stopPlaying(context, data: cItem); data.stopPlaying(context, data: cItem);
}else{ } else {
data.playVoice(context, data: cItem); data.playVoice(context, data: cItem);
} }
}) })
else else
Row( Row(
@ -320,8 +322,8 @@ class ChatBubble extends StatelessWidget {
child: Row( child: Row(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
Icon( Icon(
data.voiceController!.playerState == PlayerState.playing ? Icons.stop_circle : Icons.play_arrow, data.voiceController!.playerState == PlayerState.playing ? Icons.stop_circle : Icons.play_arrow,
color: MyColors.lightGreenColor, color: MyColors.lightGreenColor,
).paddingAll(10), ).paddingAll(10),
AudioFileWaveforms( AudioFileWaveforms(
@ -368,8 +370,8 @@ class ChatBubble extends StatelessWidget {
child: Row( child: Row(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
Icon( Icon(
data.voiceController!.playerState == PlayerState.playing ? Icons.stop_circle : Icons.play_arrow, data.voiceController!.playerState == PlayerState.playing ? Icons.stop_circle : Icons.play_arrow,
color: MyColors.white, color: MyColors.white,
).paddingAll(10), ).paddingAll(10),
AudioFileWaveforms( AudioFileWaveforms(

Loading…
Cancel
Save