From 6bf23c9ca4dac5e66835edecdaa8da841c74ba8c Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Sun, 18 Aug 2024 17:12:32 +0300 Subject: [PATCH] Fixed the issue of stucking at second patient call --- android/app/build.gradle | 1 + lib/home/app_provider.dart | 101 ++++++++++++++++++----------------- lib/home/home_screen.dart | 2 +- lib/utils/call_by_voice.dart | 32 ----------- pubspec.yaml | 3 +- 5 files changed, 55 insertions(+), 84 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index cc68d2d..fa40e32 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -30,6 +30,7 @@ android { compileSdkVersion flutter.compileSdkVersion compileOptions { + compileSdkVersion 34 sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } diff --git a/lib/home/app_provider.dart b/lib/home/app_provider.dart index 5ba7364..e3d33ae 100644 --- a/lib/home/app_provider.dart +++ b/lib/home/app_provider.dart @@ -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 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() { diff --git a/lib/home/home_screen.dart b/lib/home/home_screen.dart index f54badd..4c9e52d 100644 --- a/lib/home/home_screen.dart +++ b/lib/home/home_screen.dart @@ -151,7 +151,7 @@ class MyHomePage extends StatelessWidget { Widget build(BuildContext context) { final appProvider = context.watch(); log(appProvider.currentScreenRotation.toString()); - + // appProvider.isCallingInProgress = false; return RotatedBox( // quarterTurns: 3, quarterTurns: getTurnsByOrientation(appProvider.currentScreenRotation), diff --git a/lib/utils/call_by_voice.dart b/lib/utils/call_by_voice.dart index 0fa97ab..2661e33 100644 --- a/lib/utils/call_by_voice.dart +++ b/lib/utils/call_by_voice.dart @@ -17,13 +17,6 @@ class CallByVoice { double rate = 0.2; Future 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(); -// } } diff --git a/pubspec.yaml b/pubspec.yaml index 0a20d23..b609e8f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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