init static method
Implementation
static Future<void> init(
{String? envPath,
String? applicationPath,
String? externalUrl,
Map<String, String>? queryParameters,
Map<String, String>? headers}) async {
try {
Logger(TAG).info('Try to load configuration from $PATH_EZ_SETTINGS');
await GlobalConfiguration()
.loadFromPathIntoKey(PATH_EZ_SETTINGS, KEY_EZ_SETTINGS);
} catch (e) {
Logger(TAG).info('Could not load configuration from $PATH_EZ_SETTINGS');
}
if (envPath != null) {
Logger(TAG).info('Try to load configuration from $envPath');
await GlobalConfiguration()
.loadFromPathIntoKey(envPath, KEY_ENV_SETTINGS);
}
if (applicationPath != null) {
Logger(TAG).info('Try to load configuration from $applicationPath');
await GlobalConfiguration()
.loadFromPathIntoKey(applicationPath, KEY_APP_SETTINGS);
}
if (externalUrl != null) {
Logger(TAG).info('Try to load configuration from external $externalUrl');
try {
await GlobalConfiguration().loadFromUrlIntoKey(
externalUrl, KEY_EXTERNAL_SETTINGS,
queryParameters: queryParameters, headers: headers);
} catch (e) {
Logger(TAG).info(
'Could not load configuration from $externalUrl because of $e');
}
}
try {
Logger(TAG).info('Try to load configuration from shared preferences');
final prefs = await SharedPreferences.getInstance();
var persistent = prefs.getString(KEY_EZ_SHARED_PREFERENCES);
if (persistent != null) {
Map<String, dynamic> persistentAsMap = json.decode(persistent);
GlobalConfiguration().addValue(KEY_SP_SETTINGS, persistentAsMap);
}
} catch (e) {
Logger(TAG).info(
'Could not load configuration from shared preferences because of $e');
}
}