stringList method

List<String>? stringList(
  1. String key
)

Implementation

List<String>? stringList(String key) {
  final value = map[key];
  if (value == null) {
    return null;
  }
  if (value is! YamlList) {
    throw valueError(
      key,
      'expected a list, found ${describe(value)}. '
      'Write each item on its own line starting with "- ".',
    );
  }
  final result = <String>[];
  for (final item in value.nodes) {
    final itemValue = item.value;
    if (itemValue is String) {
      result.add(itemValue);
    } else if (itemValue is num || itemValue is bool) {
      result.add(itemValue.toString());
    } else {
      throw ConfigException(
        '${keyPath(key)}: list items must be text, found '
        '${describe(itemValue)}.',
        span: SourceSpanLike.of(item),
        file: file,
      );
    }
  }
  return result;
}