safer config reader
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/config/apply.dart';
|
||||
|
||||
class CommonConstants {
|
||||
static String apiProto = 'http';
|
||||
@@ -7,7 +7,8 @@ class CommonConstants {
|
||||
static String apiEndpoint = '/api/v1';
|
||||
static String amplitudeSecret = 'c3d75b3e2520d708440acbb16b923e79';
|
||||
static String amplitudeServerZone = 'EU';
|
||||
static String posthogApiKey = 'phc_lVhbruaZpxiQxppHBJpL36ARnPlkqbCewv6cauoceTN';
|
||||
static String posthogApiKey =
|
||||
'phc_lVhbruaZpxiQxppHBJpL36ARnPlkqbCewv6cauoceTN';
|
||||
static String posthogHost = 'https://eu.i.posthog.com';
|
||||
static Locale defaultLocale = const Locale('en');
|
||||
static String defaultCurrency = 'EUR';
|
||||
@@ -29,21 +30,36 @@ class CommonConstants {
|
||||
|
||||
// Method to apply the configuration, called by platform-specific implementations
|
||||
static void applyConfiguration(Map<String, dynamic> configJson) {
|
||||
apiProto = configJson['apiProto'] ?? apiProto;
|
||||
apiHost = configJson['apiHost'] ?? apiHost;
|
||||
apiEndpoint = configJson['apiEndpoint'] ?? apiEndpoint;
|
||||
amplitudeSecret = configJson['amplitudeSecret'] ?? amplitudeSecret;
|
||||
amplitudeServerZone = configJson['amplitudeServerZone'] ?? amplitudeServerZone;
|
||||
posthogApiKey = configJson['posthogApiKey'] ?? posthogApiKey;
|
||||
posthogHost = configJson['posthogHost'] ?? posthogHost;
|
||||
defaultLocale = Locale(configJson['defaultLocale'] ?? defaultLocale.languageCode);
|
||||
defaultCurrency = configJson['defaultCurrency'] ?? defaultCurrency;
|
||||
wsProto = configJson['wsProto'] ?? wsProto;
|
||||
wsEndpoint = configJson['wsEndpoint'] ?? wsEndpoint;
|
||||
defaultDimensionLength = configJson['defaultDimensionLength'] ?? defaultDimensionLength;
|
||||
clientId = configJson['clientId'] ?? clientId;
|
||||
if (configJson.containsKey('themeColor')) {
|
||||
themeColor = Color(int.parse(configJson['themeColor']));
|
||||
}
|
||||
applyCommonConfiguration(
|
||||
configJson,
|
||||
currentApiProto: apiProto,
|
||||
setApiProto: (value) => apiProto = value,
|
||||
currentApiHost: apiHost,
|
||||
setApiHost: (value) => apiHost = value,
|
||||
currentApiEndpoint: apiEndpoint,
|
||||
setApiEndpoint: (value) => apiEndpoint = value,
|
||||
currentAmplitudeSecret: amplitudeSecret,
|
||||
setAmplitudeSecret: (value) => amplitudeSecret = value,
|
||||
currentAmplitudeServerZone: amplitudeServerZone,
|
||||
setAmplitudeServerZone: (value) => amplitudeServerZone = value,
|
||||
currentPosthogApiKey: posthogApiKey,
|
||||
setPosthogApiKey: (value) => posthogApiKey = value,
|
||||
currentPosthogHost: posthogHost,
|
||||
setPosthogHost: (value) => posthogHost = value,
|
||||
currentDefaultLocale: defaultLocale,
|
||||
setDefaultLocale: (value) => defaultLocale = value,
|
||||
currentDefaultCurrency: defaultCurrency,
|
||||
setDefaultCurrency: (value) => defaultCurrency = value,
|
||||
currentWsProto: wsProto,
|
||||
setWsProto: (value) => wsProto = value,
|
||||
currentWsEndpoint: wsEndpoint,
|
||||
setWsEndpoint: (value) => wsEndpoint = value,
|
||||
currentDefaultDimensionLength: defaultDimensionLength,
|
||||
setDefaultDimensionLength: (value) => defaultDimensionLength = value,
|
||||
currentClientId: clientId,
|
||||
setClientId: (value) => clientId = value,
|
||||
currentThemeColor: themeColor,
|
||||
setThemeColor: (value) => themeColor = value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user