letNumOrNull function

num? letNumOrNull(
  1. dynamic input
)

Let's you convert input to a num type if possible, or returns null if the conversion cannot be performed.

Implementation

num? letNumOrNull(dynamic input) {
  if (input is num) return input;
  if (input is String) {
    final trimmed = input.trim();
    return num.tryParse(trimmed) ??
        ConvertStringToDuration(trimmed).toDurationOrNull()?.inMilliseconds;
  }
  if (input is bool) return input ? 1 : 0;
  return null;
}