toList<T> static method Null safety

List<String> toList<T>(
  1. List<T> enumValues,
  2. {bool camelCase = false}
)

Bulk convert enum values to a list

Implementation

static List<String> toList<T>(List<T> enumValues, {bool camelCase = false}) {
  final _enumList = enumValues
      .map((t) => !camelCase
          ? EnumToString.convertToString(t)
          : EnumToString.convertToString(t, camelCase: true))
      .toList();

  // I am sure there is a better way to convert a nullable list to a
  // non-nullable one, but this will do until I find out how. Happy if
  // someone want to do a PR in the meantime to correct this.
  var output = <String>[];
  for (var value in _enumList) {
    output.add(value);
  }
  return output;
}