parseFancyNumber function Null safety

int parseFancyNumber(
  1. String input
)

Implementation

int parseFancyNumber(String input) {
  input = input.trim();
  if (input.contains(',')) {
    input = input.replaceAll(',', '');
  }

  const multipliers = {'h': 100, 'k': 1000, 'ht': 100000, 'm': 1000000};
  int value;

  if (!multipliers.keys.any((m) => input.endsWith(m))) {
    value = int.parse(input);
  } else {
    final m = multipliers.keys.firstWhere((m) => input.endsWith(m));
    input = input.substring(0, input.length - m.length);
    value = num.parse(input) * multipliers[m]! as int;
  }

  return value;
}