loadHostConfig method
Implementation
Future<Map<String, dynamic>> loadHostConfig() async {
if (hostConfig != null) {
return Map<String, dynamic>.from(hostConfig!);
}
final path = hostConfigPath!;
if (path.startsWith('lib/')) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Invalid Adaptive Card hostConfigPath.'),
ErrorDescription(
'hostConfigPath was set to "$path", which points inside lib/.',
),
ErrorHint(
'Files under lib/ are not automatically available to rootBundle in release. '
'Move host config to app assets (for example "assets/host_config.json") '
'and register it in pubspec.yaml, or provide hostConfigMap instead.',
),
]);
}
try {
final hostConfigString = await rootBundle.loadString(path);
return Map<String, dynamic>.from(json.decode(hostConfigString));
} on FlutterError catch (error) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Unable to load Adaptive Card host config asset.'),
ErrorDescription('Failed to load "$path" from rootBundle.'),
ErrorHint(
'Make sure the file is declared under flutter/assets in your app pubspec '
'(for example "assets/host_config.json") or pass hostConfigMap instead.',
),
ErrorDescription('Original error: $error'),
]);
} on FormatException catch (error) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Invalid Adaptive Card host config JSON.'),
ErrorDescription('The host config loaded from "$path" is not valid JSON.'),
ErrorHint(
'Verify the JSON syntax and ensure it is a JSON object before passing it '
'as host config.',
),
ErrorDescription('Original error: $error'),
]);
}
}