addZeroPrefix method

String? addZeroPrefix()

Adds a zero prefix to the given integer if it is less than 10.

Returns a string representation of the integer with a leading '0' if the integer is a single-digit number (less than 10). If the integer is null, it returns null.

Example:

int? value = 5;
print(value.addZeroPrefix()); // Output: '05'
int? value = 15;
print(value.addZeroPrefix()); // Output: '15'
int? value = null;
print(value.addZeroPrefix()); // Output: null

Implementation

String? addZeroPrefix() {
  if (isNull()) {
    return null;
  }
  if ((this!) < 10) {
    return '0$this';
  } else {
    return toString();
  }
}