initialise method
Future<ThemeSettings>
initialise(
{ - String defaultConfigUseCase = '',
- bool loadFromConfigService = true,
})
Implementation
Future<ThemeSettings> initialise({
String defaultConfigUseCase = '',
bool loadFromConfigService = true,
}) async {
if (!configService.kIsReady) {
throw PlatformException(
code: 'NOT READY',
message: 'Configuration service not initialized',
);
}
dynamic config;
if (!core.isRegistered<LittleFishThemingService>()) {
throw PlatformException(
code: 'THEME-001',
message:
'No theming service found, please register a theming service to continue',
);
}
try {
if (loadFromConfigService) {
config = configService.getObjectValue(key: 'app_theme_settings');
}
if (config == null || config.isEmpty) {
config = getDefaultConfig(defaultConfigUseCase);
}
if (config == null || config.isEmpty) {
throw PlatformException(
code: 'NO THEME SETTINGS',
message: 'Theme settings not configured',
details: 'Configure the app_theme_settings key, to continue',
);
}
final themingService = core.get<LittleFishThemingService>();
final translatedSettings = themingService.translate(config);
_settings = translatedSettings;
try {
await themingService.initialise(translatedSettings);
} catch (e) {
_settings = null;
rethrow;
}
return settings;
} catch (e) {
logger.error(
this,
'Unable to load theme settings from server',
error: e,
stackTrace: StackTrace.current,
);
throw PlatformException(
code: 'THEME-INIT-FAIL',
message: 'Failed to load theme settings: ${e.toString()}',
stacktrace: StackTrace.current.toString(),
);
}
}