getConfig function Null safety

Future<Either<ConfigError, Config>> getConfig()

Returns content of config.yaml file or throws when the file does not exists.

Implementation

Future<Either<ConfigError, Config>> getConfig() async {
  if (await isProjectDirectory()) {
    final file = await _getConfigFile();
    final config = await file.readAsString();
    final yaml = loadYaml(config) as YamlMap;
    return Right(Config.fromYaml(yaml));
  }

  return const Left(
    ConfigError('Config file does not exists in current location'),
  );
}