getDouble static method

double? getDouble(
  1. Map map,
  2. String key, [
  3. double? defaultValue
])

Returns the value at key coerced to double, or defaultValue.

Strings are parsed via double.tryParse; ints are widened; bools map to 1.0/0.0. Returns defaultValue on missing path or failed coercion.

Implementation

static double? getDouble(Map map, String key, [double? defaultValue]) {
  final v = get(map, key);
  if (v == null) return defaultValue;
  if (v is double) return v;
  if (v is int) return v.toDouble();
  if (v is bool) return v ? 1.0 : 0.0;
  if (v is String) return double.tryParse(v) ?? defaultValue;
  return defaultValue;
}