asDouble method Null safety

double asDouble(
  1. String key,
  2. [double? defValue]
)

解析成double值

Implementation

double asDouble(String key, [double? defValue]) {
  if (this == null) return defValue ?? 0.0;
  Object? value = this![key];
  if (value == null) return defValue ?? 0.0;
  if (value is double) return value;
  try {
    double result = double.parse(value.toString());
    return result;
  } catch (e) {
    print(e);
    _print('json parse failed,exception value:\"$key\":$value');
    _printDetail('asDouble', key, this);
  }
  return defValue ?? 0.0;
}