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
compileOptions {
compileSdkVersion 34
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

@ -34,6 +34,7 @@ class AppProvider extends ChangeNotifier {
listenNetworkConnectivity();
listenAudioPlayerEvents();
getTheWidgetsConfigurationsEveryMidnight();
initializeFlutterTTS();
// await callPatientsAPI();
}
@ -51,6 +52,54 @@ class AppProvider extends ChangeNotifier {
bool isInternetConnectionAvailable = true;
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) {
isInternetConnectionAvailable = value;
notifyListeners();
@ -352,9 +401,8 @@ class AppProvider extends ChangeNotifier {
);
await voiceCaller!.startCalling(patientTicket.queueNo.trim().toString() != patientTicket.callNoStr.trim().toString()).whenComplete(() {
voiceCaller = null;
// if (isQueuePatients.isNotEmpty) {
// isQueuePatients.removeAt(0);
// }
onVoiceCompleted();
log("Completed Calling!! ${isQueuePatients.length}");
});
} else {
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() {

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

@ -17,13 +17,6 @@ class CallByVoice {
double rate = 0.2;
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("preVoice: $preVoice");
log("postVoice: $postVoice");
@ -83,30 +76,5 @@ class CallByVoice {
isVoiceActualCompletedGlobally = true;
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
blinking_text: ^1.0.2
just_audio: 0.9.31
flutter_tts: 3.6.3
# flutter_tts: 3.6.3
flutter_tts: ^4.0.2
wakelock: ^0.6.2
shared_preferences: ^2.2.1
#signalr core

Loading…
Cancel
Save