d method

double d(
  1. String key, {
  2. double defaultValue = 0,
  3. bool showLog = true,
})

获取 value 转 double

Implementation

double d(String key, {double defaultValue = 0, bool showLog = true}) {
  if (!containsKey(key)) {
    _log('当前map不存在 key:[$key]', showLog);
    return defaultValue;
  }
  final value = this[key];
  if (value is double) return value;
  if (value is int) return value.toDouble();
  if (value == null) {
    _log('[$key]的值为 null', showLog);
    return defaultValue;
  }
  final other = double.tryParse(value.toString()) ?? defaultValue;
  _log('${value.runtimeType} [$key]=$value => double:$other', showLog);
  return other;
}