import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:weather_icons/weather_icons.dart'; import 'package:wetter/models/daily_weather_model.dart'; import 'package:wetter/models/hourly_weather_model.dart'; import 'package:wetter/services/utils.dart'; class CompactWeatherData extends StatefulWidget { final DailyWeatherModel dwm; const CompactWeatherData(this.dwm, {Key? key}) : super(key: key); @override State createState() => _CompactWeatherDataState(); } class _CompactWeatherDataState extends State { @override Widget build(BuildContext context) { return Card( child: Padding( padding: const EdgeInsets.all(20), child: Column(children: [ Text( "${DateFormat('EEEE').format(widget.dwm.dateOfDay())}, ${widget.dwm.dateOfDay().day}.${widget.dwm.dateOfDay().month}.", style: Theme.of(context).textTheme.headline5, ), const SizedBox(height: 10), _weatherData(), const SizedBox(height: 20), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ _hourlyInfo(widget.dwm.hourlyWeatherModelAtTimeOfDay(4)), _hourlyInfo(widget.dwm.hourlyWeatherModelAtTimeOfDay(8)), _hourlyInfo(widget.dwm.hourlyWeatherModelAtTimeOfDay(12)), _hourlyInfo(widget.dwm.hourlyWeatherModelAtTimeOfDay(16)), _hourlyInfo(widget.dwm.hourlyWeatherModelAtTimeOfDay(20)) ], ), ]))); } Widget _hourlyInfo(HourlyWeatherModel hwm) { return Column( children: [ Text(DateFormat.Hm().format(hwm.timestamp)), const SizedBox(height: 8), Icon(weatherIcon(hwm.icon ?? "not defined")), const SizedBox(height: 14), Text("${hwm.temperature.round()} °C") ], ); } Widget _weatherData() { return Row(children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Text( "${widget.dwm.dailyMaxTemp()} °C ", style: Theme.of(context) .textTheme .titleLarge! .copyWith(fontStyle: FontStyle.normal), ), const Icon( Icons.circle, size: 10, color: Colors.grey, ), Text( " ${widget.dwm.dailyMinTemp()} °C", style: Theme.of(context) .textTheme .titleLarge! .copyWith(fontStyle: FontStyle.normal, color: Colors.grey), ) ], ), Row(crossAxisAlignment: CrossAxisAlignment.end, children: [ const Icon(WeatherIcons.barometer), const SizedBox(width: 10), Text("${widget.dwm.dailyAveragePressure().toString()} hPa") ]), const SizedBox(height: 5), Row(crossAxisAlignment: CrossAxisAlignment.end, children: [ const Icon(WeatherIcons.raindrop), const SizedBox(width: 10), Text("${widget.dwm.dailyPrecipitation().toString()} mm") ]), const SizedBox(height: 5), Row(crossAxisAlignment: CrossAxisAlignment.end, children: [ const Icon(WeatherIcons.cloud), const SizedBox(width: 10), Text("${widget.dwm.dailyAverageCloudCover().toString()} %") ]), const SizedBox(height: 5), Row(crossAxisAlignment: CrossAxisAlignment.end, children: [ const Icon(WeatherIcons.windy), const SizedBox(width: 10), Text("${widget.dwm.dailyAverageWindSpeed().toString()} km/h") ]), ], ), Expanded( child: Padding( padding: const EdgeInsets.symmetric(horizontal: 35), child: FittedBox( fit: BoxFit.contain, child: Icon(weatherIcon(widget.dwm.prevalentWeatherIcon()))))), ]); } }