Show temperature of today after starting app

This commit is contained in:
Konstantin Kollar
2022-08-31 10:53:36 +02:00
parent e2e6cab479
commit bc3dcf575c
6 changed files with 107 additions and 6 deletions
+33 -1
View File
@@ -1,4 +1,5 @@
import 'package:wetter/models/hourly_weather_model.dart';
import 'dart:math';
class DailyWeatherModel {
late List<HourlyWeatherModel> hourlyForecasts;
@@ -16,6 +17,37 @@ class DailyWeatherModel {
for (var forecast in hourlyForecasts) {
tempSum = tempSum + forecast.temperature;
}
return (tempSum / hourlyForecasts.length).toString();
return (tempSum / hourlyForecasts.length).round().toString();
}
List<int> tempList() {
List<int> temps = [];
for (HourlyWeatherModel hf in hourlyForecasts) {
temps.add(hf.temperature.round());
}
return temps;
}
String dailyMaxTemp() {
return tempList().reduce(max).toString();
}
String dailyMinTemp() {
return tempList().reduce(min).toString();
}
String? cumulatedSunshineMinutes() {
bool dataCorrect = true;
int csm = 0;
for (var hf in hourlyForecasts) {
if (hf.sunshine == null) {
return null;
} else {
csm = csm + hf.sunshine!;
}
}
if (dataCorrect) {
return csm.toString();
}
}
}