parseLevel method

Level parseLevel(
  1. dynamic value
)

Parses value to Level.

  • If value is a Map<String, dynamic>, the name and value fields are retrieved from the map.
  • If value is a String the Level with value as its name is used.
  • If value is an int the Level with value as its value is used.

If none of the above match, Level.FINE is returned.

Implementation

Level parseLevel(dynamic value) {
  if (value is Map<String, dynamic>) {
    return Level(
      value['name'] as String,
      value['value'] as int,
    );
  } else if (value is String) {
    return Level.LEVELS.firstWhere((level) => level.name == value);
  } else if (value is int) {
    return Level.LEVELS.firstWhere((level) => level.value == value);
  } else {
    return Level.FINE;
  }
}