class SourceLocationsModel { String source_name = ''; String supplierId = ''; String status = ''; String address = ''; String deliveries = '13'; String commision = ''; String phone = ''; String dbId = ''; String water_type = ''; double longitude = 0.0; double latitude = 0.0; SourceLocationsModel(); factory SourceLocationsModel.fromJson(Map json) { SourceLocationsModel rtvm = SourceLocationsModel(); rtvm.source_name = json['location_name'] ?? ''; rtvm.dbId = json['_id'] ?? ''; rtvm.supplierId = json['supplierId'] ?? ''; rtvm.status = json['status'] ?? ''; rtvm.address = json['address'] ?? ''; rtvm.phone = json['phone'] ?? ''; rtvm.water_type = json['water_type'] ?? ''; // ✅ Safely handle both int and double types var lon = json['longitude']; var lat = json['latitude']; if (lon is int) { rtvm.longitude = lon.toDouble(); } else if (lon is double) { rtvm.longitude = lon; } else { rtvm.longitude = 0.0; } if (lat is int) { rtvm.latitude = lat.toDouble(); } else if (lat is double) { rtvm.latitude = lat; } else { rtvm.latitude = 0.0; } return rtvm; } }