// 安全获取数值的扩展方法
extension MapValueExtension on Map<String, dynamic> {
  int safeGetInt(String key, {int defaultValue = 0}) {
    try {
      var value = this[key];
      if (value == null) return defaultValue;
      if (value is int) return value;
      if (value is double) return value.round();
      if (value is String) return int.tryParse(value) ?? defaultValue;
      return defaultValue;
    } catch (_) {
      return defaultValue;
    }
  }

  double safeGetDouble(String key, {double defaultValue = 0.0}) {
    try {
      var value = this[key];
      if (value == null) return defaultValue;
      if (value is double) return value;
      if (value is int) return value.toDouble();
      if (value is String) return double.tryParse(value) ?? defaultValue;
      return defaultValue;
    } catch (_) {
      return defaultValue;
    }
  }
}
