toInt static method

int toInt(
  1. dynamic value
)

Converts a value to an integer.

Example: '42' -> 42

Implementation

static int toInt(dynamic value) {
  if (value is String) {
    return int.tryParse(value) ?? 0;
  } else if (value is int) {
    return value;
  } else if (value is double) {
    return value.toInt();
  } else {
    return 0;
  }
}