asInt method

int asInt({
  1. int? def,
})

Converts the dynamic value to an integer. If conversion fails, returns the provided default value or 0. def The default value to return if conversion fails. Returns the integer representation of the dynamic value or the default value.

Implementation

int asInt({int? def}) {
  return int.tryParse(toString()) ?? def ?? 0;
}