You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
4.7 KiB
Dart
148 lines
4.7 KiB
Dart
import 'dart:developer';
|
|
|
|
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:diplomaticquarterapp/uitl/translations_delegate_base.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<dynamic> 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<String> 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<String> getGeoZones() async {
|
|
var res = await sharedPref.getStringWithDefaultValue(HMG_GEOFENCES, "[]");
|
|
return res;
|
|
}
|
|
|
|
static Future<String> 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";
|
|
|
|
Future<Object> connectHMGInternetWifi(String patientId) {
|
|
print("Invoking platform method: $hmg_internet_wifi_connect_method");
|
|
try {
|
|
return platform.invokeMethod(hmg_internet_wifi_connect_method, [patientId]);
|
|
} on PlatformException catch (e) {
|
|
print(e);
|
|
return Future.error(e);
|
|
}
|
|
}
|
|
|
|
Future<Object> connectHMGGuestWifi() {
|
|
print("Invoking platform method: $hmg_guest_wifi_connect_method");
|
|
try {
|
|
return platform.invokeMethod(hmg_guest_wifi_connect_method);
|
|
} on PlatformException catch (e) {
|
|
print(e);
|
|
return Future.error(e);
|
|
}
|
|
}
|
|
|
|
Future<Object> isHMGNetworkAvailable(String ssid) {
|
|
print("Invoking platform method: $is_hmg_network_available_method");
|
|
try {
|
|
return platform.invokeMethod(is_hmg_network_available_method, ssid);
|
|
} on PlatformException catch (e) {
|
|
print(e);
|
|
return Future.error(e);
|
|
}
|
|
}
|
|
|
|
Future<Object> enableWifiIfNot() async {
|
|
print("Invoking platform method: $enable_wifi_if_not");
|
|
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 {
|
|
print("Invoking platform method: $show_loading_method");
|
|
try {
|
|
final int result = await platform.invokeMethod(show_loading_method, [message, show]);
|
|
} on PlatformException catch (e) {
|
|
print(e);
|
|
}
|
|
}
|
|
|
|
// GEO Fences
|
|
void registerHmgGeofences() async {
|
|
final int result = await platform.invokeMethod(register_Hmg_Geofences);
|
|
}
|
|
}
|