bodyAsInteger method

int bodyAsInteger()

Converts the response data to an integer.

Returns:

  • An integer value parsed from the response data.

Implementation

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