From 366541f20f778285e840e0d42fddb20dccdf3bf1 Mon Sep 17 00:00:00 2001 From: FaizHashmiCS22 Date: Thu, 9 Jan 2025 10:26:45 +0300 Subject: [PATCH] Added connection checks --- lib/core/api.dart | 17 +++++++---------- lib/home/app_provider.dart | 16 +++++++++++++++- pubspec.yaml | 6 +++--- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/core/api.dart b/lib/core/api.dart index 6c54639..ee14684 100644 --- a/lib/core/api.dart +++ b/lib/core/api.dart @@ -27,16 +27,14 @@ class MyHttpOverrides extends HttpOverrides { class API { static getCallRequestInfoByClinicInfo(String deviceIp, - {required Function(List, List, CallConfig callConfig) onSuccess, - required Function(dynamic) onFailure}) async { + {required Function(List, List, CallConfig callConfig) onSuccess, required Function(dynamic) onFailure}) async { final body = {"ipAdress": deviceIp, "apiKey": apiKey}; bool isDevMode = false; if (isDevMode) { final Map response = testPatientsData["data"] as Map; CallConfig callConfig = CallConfig.fromJson(response["callConfig"]); - var callPatients = - (response["callPatients"] as List).map((j) => PatientTicketModel.fromJson(j)).toList().where((element) => element.callType != 0).toList(); + var callPatients = (response["callPatients"] as List).map((j) => PatientTicketModel.fromJson(j)).toList().where((element) => element.callType != 0).toList(); var isQueuePatients = callPatients.where((element) => (element.isQueue == false && element.callType != 0)).toList(); log("callPatients: ${callPatients.toString()}"); log("isQueuePatients: ${isQueuePatients.toString()}"); @@ -50,11 +48,7 @@ class API { final response = apiResp["data"]; CallConfig callConfig = CallConfig.fromJson(response["callConfig"]); - var callPatients = (response["callPatients"] as List) - .map((j) => PatientTicketModel.fromJson(j)) - .toList() - .where((element) => element.callType != 0) - .toList(); + var callPatients = (response["callPatients"] as List).map((j) => PatientTicketModel.fromJson(j)).toList().where((element) => element.callType != 0).toList(); var isQueuePatients = callPatients.where((element) => (element.isQueue == false && element.callType != 0)).toList(); callPatients.sort((a, b) => a.editedOnTimeStamp.compareTo(b.editedOnTimeStamp)); @@ -108,7 +102,10 @@ class API { body: body, onSuccess: (response, status) { if (status == 200 && response["data"] != null) { - widgetsConfigModel = (response["data"] as List).map((e) => WidgetsConfigModel.fromJson(e)).toList().first; + List list = (response["data"] as List).map((e) => WidgetsConfigModel.fromJson(e)).toList(); + if (list.isNotEmpty) { + widgetsConfigModel = list.first; + } } }, onFailure: (error, status) => log("error: ${error.toString()}")); diff --git a/lib/home/app_provider.dart b/lib/home/app_provider.dart index 6caf9e4..1581fe4 100644 --- a/lib/home/app_provider.dart +++ b/lib/home/app_provider.dart @@ -25,7 +25,18 @@ bool isVoiceActualCompletedGlobally = false; class AppProvider extends ChangeNotifier { AppProvider() { - callInitializations(); + waitForIPAndCallInitializations(); + } + + Future waitForIPAndCallInitializations() async { + while (currentDeviceIp == "") { + await getCurrentIP(); + if (currentDeviceIp != "") { + callInitializations(); + } else { + await Future.delayed(const Duration(seconds: 2)); + } + } } Future callInitializations() async { @@ -226,6 +237,9 @@ class AppProvider extends ChangeNotifier { // if (currentWidgetsConfigModel == null) return; await getInfoWidgetsConfigurationsFromServer().whenComplete(() async { + if (currentWidgetsConfigModel == null) { + return; + } if (currentWidgetsConfigModel!.isWeatherReq != null && currentWidgetsConfigModel!.isWeatherReq!) { await getWeatherDetailsFromServer(); } diff --git a/pubspec.yaml b/pubspec.yaml index 6f783bf..f09c4e5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,15 +35,15 @@ dependencies: provider: ^6.0.1 get_it: ^8.0.2 connectivity_plus: ^6.1.0 -# flutter_gifimage: ^1.0.1 + # flutter_gifimage: ^1.0.1 flutter_svg: ^2.0.14 http: ^1.2.2 blinking_text: ^1.0.2 just_audio: ^0.9.42 flutter_tts: ^4.1.0 -# flutter_tts: ^4.0.2 + # flutter_tts: ^4.0.2 wakelock_plus: ^1.2.8 - shared_preferences: ^2.2.1 + shared_preferences: ^2.3.5 #signalr core signalr_core: ^1.1.1 intl: ^0.19.0