import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/config/localized_values.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; class PlatformBridge { static const platform = const MethodChannel("HMG-Platform-Bridge"); static PlatformBridge _shared; static BuildContext _context; // // Singleton // static final PlatformBridge _singleton = PlatformBridge._internal(); // factory PlatformBridge() { // return _singleton; // } // PlatformBridge._internal(); static PlatformBridge shared() { if (_shared == null) { assert(true, "PlatformBridge is not initialized, (Initialized it by calling 'PlatformBridge.init(BuildContext))'."); } return _shared; } static void init(BuildContext context) { _context = context; _shared = PlatformBridge(); Future incoming(MethodCall methodCall) async { switch (methodCall.method) { case 'localizedValue': String key = methodCall.arguments.toString(); return localizedValue(key); case 'getGeoZones': return getGeoZones(); case 'getLogGeofenceFullUrl': return getLogGeofenceFullUrl(); case 'getDefaultHttpParameters': return getDefaultHttpParameters(); default: throw MissingPluginException('notImplemented'); } } platform.setMethodCallHandler(incoming); } //--------------------------------- // Incoming below //--------------------------------- static Future localizedValue(String forKey) async { String currentLanguage = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar'); Object localized = platformLocalizedValues[forKey][currentLanguage]; return (localized != null || (localized is String)) ? localized : forKey; } static Future getGeoZones() async { var res = await sharedPref.getStringWithDefaultValue(HMG_GEOFENCES, "[]"); return res; } static Future getLogGeofenceFullUrl() async { var res = BASE_URL + LOG_GEO_ZONES; return res; } static Future getDefaultHttpParameters() async { return BaseAppClient.defaultHttpParameters(); } //--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--// //--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--// //--------------------------------- // Outgoing below //--------------------------------- // Method Names static const hmg_internet_wifi_connect_method = "connectHMGInternetWifi"; static const hmg_guest_wifi_connect_method = "connectHMGGuestWifi"; static const is_hmg_network_available_method = "isHMGNetworkAvailable"; static const enable_wifi_if_not = "enableWifiIfNot"; static const show_loading_method = "loading"; static const register_Hmg_Geofences = "registerHmgGeofences"; static const un_register_Hmg_Geofences = "unRegisterHmgGeofences"; Future connectHMGInternetWifi(String patientId) { try { return platform.invokeMethod(hmg_internet_wifi_connect_method, [patientId]); } on PlatformException catch (e) { print(e); return Future.error(e); } } Future connectHMGGuestWifi() { try { return platform.invokeMethod(hmg_guest_wifi_connect_method); } on PlatformException catch (e) { print(e); return Future.error(e); } } Future isHMGNetworkAvailable(String ssid) { try { return platform.invokeMethod(is_hmg_network_available_method, ssid); } on PlatformException catch (e) { print(e); return Future.error(e); } } Future enableWifiIfNot() async { try { return platform.invokeMethod(enable_wifi_if_not); } on PlatformException catch (e) { print(e); return Future.error(e); } } void showLoading(String message, bool show) async { try { var result = await platform.invokeMethod(show_loading_method, [message, show]); } on PlatformException catch (e) { print(e); } } // GEO Fences void registerHmgGeofences() async { var result = await platform.invokeMethod(register_Hmg_Geofences); } void unRegisterHmgGeofences() async { var result = await platform.invokeMethod(un_register_Hmg_Geofences); } }