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 {
ScrollController scrollController = ScrollController();
TextEditingController message = TextEditingController();
TextEditingController search = TextEditingController();
List<SingleUserChatModel> userChatHistory = [];
@ -1180,7 +1181,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
chatReplyId: null,
isAttachment: true,
isReply: isMsgReply,
voicFile: voiceFile,
voiceFile: voiceFile,
);
notifyListeners();
}
@ -1198,7 +1199,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
bool? isReply,
bool? isAttachment,
int? chatReplyId,
File? voicFile}) async {
File? voiceFile}) async {
Uuid uuid = const Uuid();
String contentNo = uuid.v4();
String msg = msgText!;
@ -1219,10 +1220,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
fileTypeResponse: isAttachment!
? FileTypeResponse(
fileTypeId: fileTypeId,
fileTypeName: getFileExtension(voicFile!.path).toString(),
fileTypeName: getFileExtension(voiceFile!.path).toString(),
fileKind: "file",
fileName: msgText,
fileTypeDescription: getFileTypeDescription(getFileExtension(voicFile!.path).toString()),
fileTypeDescription: getFileTypeDescription(getFileExtension(voiceFile!.path).toString()),
)
: null,
image: null,
@ -1293,7 +1294,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
file.readAsBytesSync();
Utils.hideLoading(context);
await data.voiceController!.preparePlayer(file.path, 1.0);
data.voiceController!.startPlayer(finishMode: FinishMode.pause);
data.voiceController!.startPlayer(finishMode: FinishMode.stop);
notifyListeners();
} catch (e) {
Utils.showToast("Cannot open file.");
@ -1301,7 +1302,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
}
void stopPlaying(BuildContext context, {required SingleUserChatModel data}) async {
await data.voiceController!.pausePlayer();
await data.voiceController!.stopPlayer();
notifyListeners();
}
@ -1316,9 +1317,24 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
return file.path;
}
// data.scrollController.animateTo(
// data.scrollController.position.maxScrollExtent,
// duration: const Duration(milliseconds: 100),
// curve: Curves.easeOut,
// );
void scrollToMsg(SingleUserChatModel data) {
if (data.userChatReplyResponse != null && data.userChatReplyResponse!.userChatHistoryId != null) {
int index = userChatHistory.indexWhere((SingleUserChatModel element) => element.userChatHistoryId == data.userChatReplyResponse!.userChatHistoryId);
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)
ClipRRect(
borderRadius: BorderRadius.circular(5.0),
@ -118,9 +120,9 @@ class ChatBubble extends StatelessWidget {
).paddingOnly(bottom: 4),
if (fileTypeID == 13)
currentWaveBubble(context, cItem).onPress(() {
if(cItem.voiceController!.playerState == PlayerState.playing){
if (cItem.voiceController!.playerState == PlayerState.playing) {
data.stopPlaying(context, data: cItem);
}else{
} else {
data.playVoice(context, data: cItem);
}
})
@ -208,6 +210,7 @@ class ChatBubble extends StatelessWidget {
),
),
).paddingOnly(bottom: 7).onPress(() {
data.scrollToMsg(cItem);
}),
if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3)
ClipRRect(
@ -226,12 +229,11 @@ class ChatBubble extends StatelessWidget {
).paddingOnly(bottom: 4),
if (fileTypeID == 13)
recipetWaveBubble(context, cItem).onPress(() {
if(cItem.voiceController!.playerState == PlayerState.playing){
if (cItem.voiceController!.playerState == PlayerState.playing) {
data.stopPlaying(context, data: cItem);
}else{
} else {
data.playVoice(context, data: cItem);
}
})
else
Row(

Loading…
Cancel
Save