getRequiredValueFromMap<T> static method

T getRequiredValueFromMap<T>(
  1. Map<String, dynamic> map,
  2. String camelCaseKey,
  3. String snakeCaseKey
)

Helper method to get a required value from a map that may contain either camelCase or snake_case keys. Throws a FormatException if the key is not found.

Implementation

static T getRequiredValueFromMap<T>(
  Map<String, dynamic> map,
  String camelCaseKey,
  String snakeCaseKey,
) {
  final value = map[camelCaseKey] ?? map[snakeCaseKey];
  if (value == null) {
    throw FormatException('Required field "$camelCaseKey" is missing from map');
  }
  return value as T;
}