This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
generated from yumemi-inc/flutter-training-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from warahiko/feature/fetch_with_json
詳細な予報結果の表示
- Loading branch information
Showing
4 changed files
with
53 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
enum Forecast { | ||
sunny(image: 'assets/sunny.svg'), | ||
cloudy(image: 'assets/cloudy.svg'), | ||
rainy(image: 'assets/rainy.svg'), | ||
; | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter_training/weather.dart'; | ||
|
||
class Forecast { | ||
const Forecast({ | ||
required this.image, | ||
required this.weather, | ||
required this.maxTemperature, | ||
required this.minTemperature, | ||
}); | ||
|
||
factory Forecast.from(String name) { | ||
return Forecast.values.singleWhere( | ||
(element) => element.name == name, | ||
orElse: () => throw Exception('No enum value for `$name`.'), | ||
factory Forecast.from(String jsonString) { | ||
final decoded = jsonDecode(jsonString) as Map<String, dynamic>; | ||
|
||
return Forecast( | ||
weather: Weather.from(decoded['weather_condition'] as String), | ||
minTemperature: decoded['min_temperature'] as int, | ||
maxTemperature: decoded['max_temperature'] as int, | ||
); | ||
} | ||
|
||
final String image; | ||
final Weather weather; | ||
final int maxTemperature; | ||
final int minTemperature; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
enum Weather { | ||
sunny(image: 'assets/sunny.svg'), | ||
cloudy(image: 'assets/cloudy.svg'), | ||
rainy(image: 'assets/rainy.svg'), | ||
; | ||
|
||
const Weather({ | ||
required this.image, | ||
}); | ||
|
||
factory Weather.from(String name) { | ||
return Weather.values.singleWhere( | ||
(element) => element.name == name, | ||
orElse: () => throw Exception('No enum value for `$name`.'), | ||
); | ||
} | ||
|
||
final String image; | ||
} |