WeatherInfo.fromJson constructor

WeatherInfo.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory WeatherInfo.fromJson(Map<String, dynamic> json) {
  return WeatherInfo(
    city: json['city'] ?? '未知城市',
    temperature: (json['temperature'] ?? 20).toDouble(),
    condition: json['condition'] ?? '晴',
    description: json['description'] ?? '天气不错',
    humidity: json['humidity'] ?? 50,
    windSpeed: (json['windSpeed'] ?? 0).toDouble(),
    date: json['date'] != null
      ? DateTime.parse(json['date'])
      : DateTime.now(),
    minTemp: json['minTemp'] ?? 15,
    maxTemp: json['maxTemp'] ?? 25,
  );
}