tryGetEnum<T extends Enum> method

T? tryGetEnum<T extends Enum>(
  1. int index, {
  2. required T parser(
    1. dynamic
    ),
  3. List<int>? alternativeIndices,
  4. dynamic innerMapKey,
  5. int? innerIndex,
  6. T? defaultValue,
  7. Map<String, dynamic>? debugInfo,
})

Tries to convert the element at index (or fallback indices) to an enum using parser.

Implementation

T? tryGetEnum<T extends Enum>(
  int index, {
  required T Function(dynamic) parser,
  List<int>? alternativeIndices,
  dynamic innerMapKey,
  int? innerIndex,
  T? defaultValue,
  Map<String, dynamic>? debugInfo,
}) {
  final info = <String, dynamic>{};
  if (debugInfo != null && debugInfo.isNotEmpty) {
    info.addAll(debugInfo);
  }
  info['index'] = index;
  if (alternativeIndices != null && alternativeIndices.isNotEmpty) {
    info['altIndexes'] = alternativeIndices;
  }
  return ConvertObjectImpl.tryToEnum<T>(
    _firstForIndices(index, alternativeIndices: alternativeIndices),
    parser: parser,
    mapKey: innerMapKey,
    listIndex: innerIndex,
    defaultValue: defaultValue,
    debugInfo: info,
  );
}