secondsDurationFromJson static method

Duration? secondsDurationFromJson(
  1. dynamic value
)

Converts a value of seconds to a Duration object.

  • double => floor of value, passed to Duration
  • integer => value passed to Duration
  • string => value parsed as int, passed to Duration
  • boolean => null

Implementation

static Duration? secondsDurationFromJson(dynamic value) {
    try {
        switch(value.runtimeType) {
            case bool: return null;
            case int: return Duration(seconds: (value as int));
            case double: return Duration(seconds: (value as double).floor());
            case String: return Duration(seconds: int.parse(value as String));
            default: return null;
        }
    } catch(_) {};
    return null;
}