getConfig function
Get config from pubspec.yaml
or flutter_native_splash.yaml
Implementation
Map<String, dynamic> getConfig({
required String? configFile,
required String? flavor,
}) {
// It is important that the flavor setup occurs as soon as possible.
// So before we generate anything, we need to setup the flavor (even if it's the default one).
_flavorHelper = _FlavorHelper(flavor);
// if `flutter_native_splash.yaml` exists use it as config file, otherwise use `pubspec.yaml`
String filePath;
if (configFile != null) {
if (File(configFile).existsSync()) {
filePath = configFile;
} else {
print('The config file `$configFile` was not found.');
exit(1);
}
} else if (_flavorHelper.flavor != null) {
filePath = 'flutter_native_splash-${_flavorHelper.flavor}.yaml';
} else if (File('flutter_native_splash.yaml').existsSync()) {
filePath = 'flutter_native_splash.yaml';
} else {
filePath = 'pubspec.yaml';
}
final Map yamlMap = loadYaml(File(filePath).readAsStringSync()) as Map;
if (yamlMap['flutter_native_splash'] is! Map) {
throw Exception(
'Your `$filePath` file does not contain a '
'`flutter_native_splash` section.',
);
}
// yamlMap has the type YamlMap, which has several unwanted side effects
return _yamlToMap(yamlMap['flutter_native_splash'] as YamlMap);
}