asListStringOrNull function

List<String>? asListStringOrNull(
  1. dynamic json,
  2. String key, {
  3. String fromJson(
    1. dynamic json
    )?,
})

==================== ListString conversions

Returns a List if the value at key is a list of strings, otherwise null.

Implementation

/// Returns a List if the value at [key] is a list of strings, otherwise null.
List<String>? asListStringOrNull(dynamic json, String key,
    {String Function(dynamic json)? fromJson}) {
  final list = asListOrNull<dynamic>(json, key, fromJson: fromJson)
      ?.map(toStringOrNull)
      .toList();
  if (list == null || list.any((element) => element == null)) return null;
  return list.whereType<String>().toList();
}