toNullableDuration static method
Converts value into Date or returns null when conversion is not possible.
value
the value to convert. Returns Date value or null when conversion is not supported.
Implementation
static Duration? toNullableDuration(value) {
if (value == null) return null;
if (value is Duration) return value;
if (value is Duration) value = value.inMilliseconds;
if (value is num) return Duration(milliseconds: value.toInt());
var parsed = double.tryParse(value.toString());
var result = parsed != null ? parsed.truncate() : parsed;
return result != null ? Duration(milliseconds: result.toInt()) : null;
}