indexOf<T> static method Null safety

int indexOf<T>(
  1. List<T> enumValues,
  2. String value
)

Get the index of the enum value

Pass in the enum values to argument one, so TestEnum.values Pass in the matching string to argument 2, so "valueOne"

Eg. final index = EnumToString.indexOf(TestEnum.values, "valueOne") index == 0 //true

Implementation

static int indexOf<T>(List<T> enumValues, String value) {
  final fromStringResult = fromString<T>(enumValues, value);
  if (fromStringResult == null) {
    return -1;
  } else {
    return enumValues.indexOf(fromStringResult);
  }
}