fromMap static method

ReciterError fromMap(
  1. Map<String, dynamic> map
)

Implementation

static ReciterError fromMap(Map<String, dynamic> map) {
  final rawErrorType = map['errorType'] ?? map['errorTypeIndex'];
  final ErrorCategory errorType = (rawErrorType is int)
      ? ErrorCategory.values[rawErrorType]
      : (rawErrorType is String
          ? ErrorCategory.values.firstWhere(
              (e) => e.name == rawErrorType,
              orElse: () => ErrorCategory.normal,
            )
          : ErrorCategory.normal);

  final rawSpeech = map['speechErrorType'] ?? map['speechErrorTypeIndex'];
  final SpeechErrorType speechErrorType = (rawSpeech is int)
      ? SpeechErrorType.values[rawSpeech]
      : (rawSpeech is String
          ? SpeechErrorType.values.firstWhere(
              (e) => e.name == rawSpeech,
              orElse: () => SpeechErrorType.replace,
            )
          : SpeechErrorType.replace);

  final rawStatus = map['durationStatus'] ?? map['durationStatusIndex'];
  final TajweedDurationStatus? durationStatus = (rawStatus is int)
      ? TajweedDurationStatus.values[rawStatus]
      : (rawStatus is String
          ? TajweedDurationStatus.values.firstWhere(
              (e) => e.name == rawStatus,
              orElse: () => TajweedDurationStatus.valid,
            )
          : null);

  return ReciterError(
    errorType: errorType,
    speechErrorType: speechErrorType,
    durationStatus: durationStatus,
    expectedPh: map['expectedPh'] as String? ?? '',
    predictedPh: map['predictedPh'] as String? ?? '',
    expectedRule: _ruleFromMap(map['expectedRule'] as Map<String, dynamic>?),
    predictedRule:
        _ruleFromMap(map['predictedRule'] as Map<String, dynamic>?),
    expectedDuration: (map['expectedDuration'] as num?)?.toDouble(),
    actualDuration: (map['actualDuration'] as num?)?.toDouble(),
  );
}