bodyAsNumber method

num bodyAsNumber()

Converts the response data to a number.

Returns:

  • A number parsed from the response data.

Implementation

num bodyAsNumber() {
  if (data is num) {
    return data;
  }
  if (data is String) {
    return num.tryParse(data) ??
        (throw FormatException("Invalid number: $data"));
  }
  throw FormatException("Cannot convert ${data.runtimeType} to num.");
}