Fixed the issue of stucking at second patient call

master
Faiz Hashmi 1 year ago
parent 759e9d388a
commit 6bf23c9ca4

@ -30,6 +30,7 @@ android {
compileSdkVersion flutter.compileSdkVersion compileSdkVersion flutter.compileSdkVersion
compileOptions { compileOptions {
compileSdkVersion 34
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }

@ -34,6 +34,7 @@ class AppProvider extends ChangeNotifier {
listenNetworkConnectivity(); listenNetworkConnectivity();
listenAudioPlayerEvents(); listenAudioPlayerEvents();
getTheWidgetsConfigurationsEveryMidnight(); getTheWidgetsConfigurationsEveryMidnight();
initializeFlutterTTS();
// await callPatientsAPI(); // await callPatientsAPI();
} }
@ -51,6 +52,54 @@ class AppProvider extends ChangeNotifier {
bool isInternetConnectionAvailable = true; bool isInternetConnectionAvailable = true;
bool isApiCallNeeded = false; bool isApiCallNeeded = false;
initializeFlutterTTS() async {
flutterTts.setCompletionHandler(() => onVoiceCompleted());
}
Future<void> onVoiceCompleted() async {
log("My Value is in setCompletionHandler: $isVoiceActualCompletedGlobally");
log("isQueuePatients.length in setCompletionHandler: ${isQueuePatients.length}");
if (!isVoiceActualCompletedGlobally) {
return;
}
if (isQueuePatients.isNotEmpty) {
await Future.delayed(Duration(seconds: patientCallConfigurations.concurrentCallDelaySec)).whenComplete(
() async {
PatientTicketModel temp = PatientTicketModel();
if (patientTickets.isNotEmpty && isQueuePatients.length > 1) {
temp = patientTickets.elementAt(0);
patientTickets.removeAt(0);
}
notifyListeners();
if (isQueuePatients.isNotEmpty) {
isQueuePatients.removeAt(0);
}
if (patientTickets.isNotEmpty && isQueuePatients.length > 1) {
patientTickets.add(temp);
}
notifyListeners();
if (isQueuePatients.isNotEmpty) {
await voiceCallPatientTicket(patientTickets.first, "setCompletionHandler");
updatePatientTicket(patientTickets.first);
}
},
);
}
log("here logg: ${isQueuePatients.length}");
if (isQueuePatients.isEmpty) {
isCallingInProgress = false;
}
if (isApiCallNeeded && isQueuePatients.isEmpty) {
log("Setting isCallingInProgress : $isCallingInProgress");
Timer(Duration(seconds: patientCallConfigurations.concurrentCallDelaySec), () async {
await callPatientsAPI();
isApiCallNeeded = false;
});
}
}
updateInternetConnection(bool value) { updateInternetConnection(bool value) {
isInternetConnectionAvailable = value; isInternetConnectionAvailable = value;
notifyListeners(); notifyListeners();
@ -352,9 +401,8 @@ class AppProvider extends ChangeNotifier {
); );
await voiceCaller!.startCalling(patientTicket.queueNo.trim().toString() != patientTicket.callNoStr.trim().toString()).whenComplete(() { await voiceCaller!.startCalling(patientTicket.queueNo.trim().toString() != patientTicket.callNoStr.trim().toString()).whenComplete(() {
voiceCaller = null; voiceCaller = null;
// if (isQueuePatients.isNotEmpty) { onVoiceCompleted();
// isQueuePatients.removeAt(0); log("Completed Calling!! ${isQueuePatients.length}");
// }
}); });
} else { } else {
isCallingInProgress = false; isCallingInProgress = false;
@ -418,53 +466,6 @@ class AppProvider extends ChangeNotifier {
} }
} }
}); });
flutterTts.setCompletionHandler(() async {
log("My Value is in setCompletionHandler: $isVoiceActualCompletedGlobally");
log("isQueuePatients.length in setCompletionHandler: ${isQueuePatients.length}");
if (!isVoiceActualCompletedGlobally) {
return;
}
if (isQueuePatients.isNotEmpty) {
// final length = isQueuePatients.length;
// for (int i = 0; i < length; i++) {
await Future.delayed(Duration(seconds: patientCallConfigurations.concurrentCallDelaySec)).whenComplete(
() async {
PatientTicketModel temp = PatientTicketModel();
if (patientTickets.isNotEmpty && isQueuePatients.length > 1) {
temp = patientTickets.elementAt(0);
patientTickets.removeAt(0);
}
notifyListeners();
if (isQueuePatients.isNotEmpty) {
isQueuePatients.removeAt(0);
}
if (patientTickets.isNotEmpty && isQueuePatients.length > 1) {
patientTickets.add(temp);
}
notifyListeners();
if (isQueuePatients.isNotEmpty) {
await voiceCallPatientTicket(patientTickets.first, "setCompletionHandler");
updatePatientTicket(patientTickets.first);
}
},
);
// }
}
log("here logg: ${isQueuePatients.length}");
if (isQueuePatients.isEmpty) {
isCallingInProgress = false;
}
if (isApiCallNeeded && isQueuePatients.isEmpty) {
log("Setting isCallingInProgress : $isCallingInProgress");
Timer(Duration(seconds: patientCallConfigurations.concurrentCallDelaySec), () async {
await callPatientsAPI();
isApiCallNeeded = false;
});
}
});
} }
// updatePatientTickets() { // updatePatientTickets() {

@ -151,7 +151,7 @@ class MyHomePage extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final appProvider = context.watch<AppProvider>(); final appProvider = context.watch<AppProvider>();
log(appProvider.currentScreenRotation.toString()); log(appProvider.currentScreenRotation.toString());
// appProvider.isCallingInProgress = false;
return RotatedBox( return RotatedBox(
// quarterTurns: 3, // quarterTurns: 3,
quarterTurns: getTurnsByOrientation(appProvider.currentScreenRotation), quarterTurns: getTurnsByOrientation(appProvider.currentScreenRotation),

@ -17,13 +17,6 @@ class CallByVoice {
double rate = 0.2; double rate = 0.2;
Future<void> startCalling(bool isClinicNameAdded) async { Future<void> startCalling(bool isClinicNameAdded) async {
// log("langs1: ${(await flutterTts.getVoices).toString()}");
// log("langs2: ${(await flutterTts.areLanguagesInstalled(["en-AU", "ar-AR"])).toString()}");
// log("langs3: ${(await flutterTts.getDefaultVoice).toString()}");
// log("langs3: ${(await flutterTts.getLanguages).toString()}");
// log("langs4: ${(await flutterTts.setVoice({"name": "kn-in-x-knf-network", "locale": "kn-IN"})).toString()}");
// log("langs5: ${(await flutterTts.getEngines).toString()}");
log("lang: $lang"); log("lang: $lang");
log("preVoice: $preVoice"); log("preVoice: $preVoice");
log("postVoice: $postVoice"); log("postVoice: $postVoice");
@ -83,30 +76,5 @@ class CallByVoice {
isVoiceActualCompletedGlobally = true; isVoiceActualCompletedGlobally = true;
await flutterTts.speak(postVoice); await flutterTts.speak(postVoice);
} }
// // Create Ticket Number Voice Players
// final characters = ticketNo.characters.toList();
// for (int i = 0; i < characters.length; i++) {
// final no = characters[i];
// if (no.isNotEmpty && no != "-" && no != "_" && no != " ") {
//
// await _player.stop();
// await _player.setAsset('assets/voice_$lang/${no.toUpperCase()}.mp3');
// await _player.play();
// }
// }
// Create Post Voice Players
// if (postVoice != null && postVoice.isNotEmpty) {
// await Future.delayed(const Duration(milliseconds: 1000));
//
// await _player.stop();
// await _player.setAsset('assets/voice_$lang/$postVoice');
// await _player.play();
// }
} }
// stop() async {
// await _player.stop();
// }
} }

@ -40,7 +40,8 @@ dependencies:
http: ^0.13.0 http: ^0.13.0
blinking_text: ^1.0.2 blinking_text: ^1.0.2
just_audio: 0.9.31 just_audio: 0.9.31
flutter_tts: 3.6.3 # flutter_tts: 3.6.3
flutter_tts: ^4.0.2
wakelock: ^0.6.2 wakelock: ^0.6.2
shared_preferences: ^2.2.1 shared_preferences: ^2.2.1
#signalr core #signalr core

Loading…
Cancel
Save