fetchConfig method
Fetch the request configuration from the backend and advance to the welcome step once loaded.
Implementation
Future<void> fetchConfig() async {
_loading = true;
_progress = 0;
notifyListeners();
try {
updateProgress(5);
final config = await _apiService.fetchRequestConfig();
updateProgress(72);
_requestConfig = config;
// Check if request returned an error (e.g. PROCESSED)
if (config['error'] == true) {
_configErrorMessage = config['message'] as String?;
_loading = false;
goToStep(DataleonFlowStep.alreadyProcessed);
return;
}
final workspaceString =
config['result']?['metadata']?['workspace'] as String?;
if (workspaceString != null && workspaceString.isNotEmpty) {
_workspace = jsonDecode(workspaceString) as Map<String, dynamic>;
}
final language = config['result']?['metadata']?['language'] as String? ??
dashboardConfiguration['languageApp'] as String?;
if (language != null && language.isNotEmpty) {
const _iso3LangToIso2 = <String, String>{
'fra': 'fr', 'eng': 'en', 'ara': 'ar', 'deu': 'de',
'ita': 'it', 'por': 'pt', 'spa': 'es', 'nld': 'nl',
};
final normalized = language.toLowerCase();
_languageCode = _iso3LangToIso2[normalized] ?? language;
}
try {
final contentsData = await _apiService.fetchContentsConfig();
final langContent = contentsData[_languageCode] ??
contentsData[_languageCode.split('-').first] ??
contentsData['fr'];
if (langContent is Map<String, dynamic>) {
_contentsConfig = langContent;
}
} catch (_) {}
updateProgress(100);
try {
await _loadCustomFonts();
} catch (_) {}
// Keep the loader visible after reaching 100%.
await Future.delayed(const Duration(milliseconds: 2600));
_loading = false;
goToStep(DataleonFlowStep.welcome);
} catch (e) {
_configErrorMessage = e.toString();
_loading = false;
// 403 / PROCESSED → alreadyProcessed, other errors → error page
if (e is DataleonApiException && e.statusCode == 403) {
goToStep(DataleonFlowStep.alreadyProcessed);
} else {
goToStep(DataleonFlowStep.error);
}
}
}