@ -2,7 +2,7 @@ import 'dart:async';
import ' dart:developer ' ;
import ' dart:io ' ;
import ' package:connectivity /connectivity.dart' ;
import ' package:connectivity _plus /connectivity_plus .dart' ;
import ' package:flutter/cupertino.dart ' ;
import ' package:flutter_tts/flutter_tts.dart ' ;
import ' package:intl/intl.dart ' ;
@ -25,7 +25,18 @@ bool isVoiceActualCompletedGlobally = false;
class AppProvider extends ChangeNotifier {
AppProvider ( ) {
callInitializations ( ) ;
waitForIPAndCallInitializations ( ) ;
}
Future < void > waitForIPAndCallInitializations ( ) async {
while ( currentDeviceIp = = " " ) {
await getCurrentIP ( ) ;
if ( currentDeviceIp ! = " " ) {
await callInitializations ( ) ;
} else {
await Future . delayed ( const Duration ( seconds: 2 ) ) ;
}
}
}
Future < void > callInitializations ( ) async {
@ -87,7 +98,7 @@ class AppProvider extends ChangeNotifier {
) ;
}
logger . i ( " here logger.ig : ${ isQueuePatients . length } " ) ;
logger . i ( " isQueuePatients : ${ isQueuePatients . length } " ) ;
if ( isQueuePatients . isEmpty ) {
isCallingInProgress = false ;
@ -198,7 +209,9 @@ class AppProvider extends ChangeNotifier {
Future < void > getPrayerDetailsFromServer ( ) async {
PrayersWidgetModel ? prayersWidgetModel = await API . getPrayerDetailsFromServer (
latitude: currentWidgetsConfigModel ! . projectLatitude ? ? 0 , longitude: currentWidgetsConfigModel ! . projectLongitude ? ? 0 , onFailure: ( error ) = > logger . i ( " Api call failed with this error: ${ error . toString ( ) } " ) ) ;
latitude: currentWidgetsConfigModel ! . projectLatitude ? ? 0 ,
longitude: currentWidgetsConfigModel ! . projectLongitude ? ? 0 ,
onFailure: ( error ) = > logger . i ( " Api call failed with this error: ${ error . toString ( ) } " ) ) ;
if ( prayersWidgetModel ! = null ) {
currentPrayersWidgetModel = prayersWidgetModel ;
@ -224,13 +237,16 @@ class AppProvider extends ChangeNotifier {
/ / if ( currentWidgetsConfigModel = = null ) return ;
await getInfoWidgetsConfigurationsFromServer ( ) . whenComplete ( ( ) async {
if ( currentWidgetsConfigModel ! . isWeatherReq ! ) {
if ( currentWidgetsConfigModel = = null ) {
return ;
}
if ( currentWidgetsConfigModel ! . isWeatherReq ! = null & & currentWidgetsConfigModel ! . isWeatherReq ! ) {
await getWeatherDetailsFromServer ( ) ;
}
if ( currentWidgetsConfigModel ! . isPrayerTimeReq ! ) {
if ( currentWidgetsConfigModel ! . isPrayerTimeReq ! = null & & currentWidgetsConfigModel ! . isPrayerTimeReq ! ) {
await getPrayerDetailsFromServer ( ) ;
}
if ( currentWidgetsConfigModel ! . isRssFeedReq ! ) {
if ( currentWidgetsConfigModel ! . isRssFeedReq ! = null & & currentWidgetsConfigModel ! . isRssFeedReq ! ) {
await getRssFeedDetailsFromServer ( ) ;
}
} ) ;
@ -243,6 +259,9 @@ class AppProvider extends ChangeNotifier {
Future < void > getTheWidgetsConfigurationsEveryMidnight ( ) async {
if ( currentWidgetsConfigModel = = null ) return ;
if ( ! ( currentWidgetsConfigModel ! . isWeatherReq ? ? false ) & & ! ( currentWidgetsConfigModel ! . isPrayerTimeReq ? ? false ) & & ! ( currentWidgetsConfigModel ! . isRssFeedReq ? ? false ) ) {
return ;
}
if ( ! currentWidgetsConfigModel ! . isWeatherReq ! & & ! currentWidgetsConfigModel ! . isPrayerTimeReq ! & & ! currentWidgetsConfigModel ! . isRssFeedReq ! ) {
return ;
}
@ -494,7 +513,13 @@ class AppProvider extends ChangeNotifier {
onDisconnect ( exception ) {
logger . i ( " SignalR: onDisconnect " ) ;
signalRHelper . startSignalRConnection ( currentDeviceIp , onUpdateAvailable: onPingReceived , onConnect: onConnect , onConnecting: onConnecting , onDisconnect: onDisconnect , ) ;
signalRHelper . startSignalRConnection (
currentDeviceIp ,
onUpdateAvailable: onPingReceived ,
onConnect: onConnect ,
onConnecting: onConnecting ,
onDisconnect: onDisconnect ,
) ;
}
onConnecting ( ) {
@ -502,9 +527,10 @@ class AppProvider extends ChangeNotifier {
}
listenNetworkConnectivity ( ) async {
Connectivity ( ) . onConnectivityChanged . listen ( ( event) async {
switch ( event ) {
Connectivity ( ) . onConnectivityChanged . listen ( ( List< ConnectivityResult > event) async {
switch ( event .first ) {
case ConnectivityResult . wifi:
case ConnectivityResult . ethernet:
updateInternetConnection ( true ) ;
await getCurrentIP ( ) ;
if ( signalRHelper . connection ! = null ) {
@ -517,6 +543,16 @@ class AppProvider extends ChangeNotifier {
break ;
case ConnectivityResult . mobile:
break ;
case ConnectivityResult . bluetooth:
/ / TODO: Handle this case .
break ;
/ / TODO: Handle this case .
case ConnectivityResult . vpn:
/ / TODO: Handle this case .
break ;
case ConnectivityResult . other:
/ / TODO: Handle this case .
break ;
}
} ) ;
}