getConfig function
Get config from pubspec.yaml
or splash_screen_view.yaml
Implementation
Map<String, dynamic> getConfig({String? configFile}) {
// if `splash_screen_view.yaml` exists use it as config file, otherwise use `pubspec.yaml`
String filePath;
if (configFile != null && File(configFile).existsSync()) {
filePath = configFile;
} else if (File('splash_screen_view.yaml').existsSync()) {
filePath = 'splash_screen_view.yaml';
} else {
filePath = 'pubspec.yaml';
}
final Map yamlMap = loadYaml(File(filePath).readAsStringSync());
if (!(yamlMap['splash_screen_view'] is Map)) {
throw Exception('Your `$filePath` file does not contain a '
'`splash_screen_view` section.');
}
// yamlMap has the type YamlMap, which has several unwanted side effects
final config = <String, dynamic>{};
for (MapEntry<dynamic, dynamic> entry
in yamlMap['splash_screen_view'].entries) {
if (entry.value is YamlList) {
var list = <String>[];
(entry.value as YamlList).forEach((dynamic value) {
if (value is String) {
list.add(value);
}
});
config[entry.key] = list;
} else {
config[entry.key] = entry.value;
}
}
return config;
}