From 324881c9d547fb8a371639f1799587827d77e364 Mon Sep 17 00:00:00 2001 From: Feichtmeier Date: Sun, 28 Apr 2024 16:50:40 +0200 Subject: [PATCH 1/2] Display day in today chart --- lib/src/l10n/app_de.arb | 3 +- lib/src/l10n/app_en.arb | 3 +- lib/src/weather/view/today_chart.dart | 61 +++++++++++++++++---------- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/lib/src/l10n/app_de.arb b/lib/src/l10n/app_de.arb index c9452b1..30f9fd5 100644 --- a/lib/src/l10n/app_de.arb +++ b/lib/src/l10n/app_de.arb @@ -9,5 +9,6 @@ "enterValidApiKey": "Bitte gib einen (gültigen) API Schlüssel ein", "hourly": "Stündlich", "daily": "Täglich", - "now": "Jetzt" + "now": "Jetzt", + "today": "Heute" } \ No newline at end of file diff --git a/lib/src/l10n/app_en.arb b/lib/src/l10n/app_en.arb index 5b6d8f9..d365bb0 100644 --- a/lib/src/l10n/app_en.arb +++ b/lib/src/l10n/app_en.arb @@ -9,5 +9,6 @@ "enterValidApiKey": "Please enter a (valid) API key", "hourly": "Hourly", "daily": "Daily", - "now": "Now" + "now": "Now", + "today": "Today" } \ No newline at end of file diff --git a/lib/src/weather/view/today_chart.dart b/lib/src/weather/view/today_chart.dart index 4bcf81b..4b24d72 100644 --- a/lib/src/weather/view/today_chart.dart +++ b/lib/src/weather/view/today_chart.dart @@ -7,6 +7,7 @@ import 'package:yaru/yaru.dart'; import '../../../constants.dart'; import '../../build_context_x.dart'; +import '../../l10n/l10n.dart'; import '../weather_data_x.dart'; import '../weather_model.dart'; import 'error_view.dart'; @@ -42,7 +43,7 @@ class _TodayChartState extends State { @override Widget build(BuildContext context) { final forecast = - watchPropertyValue((WeatherModel m) => m.notTodayFullForecast); + watchPropertyValue((WeatherModel m) => m.fiveDaysForCast ?? []); final mq = context.mq; final cityName = watchPropertyValue((WeatherModel m) => m.lastLocation); @@ -76,7 +77,7 @@ class _TodayChartState extends State { width: forecast.length * 100, height: 400, child: LineChart( - mainData(forecast), + mainData(forecast: forecast, data: data), ), ), ), @@ -123,29 +124,41 @@ class _TodayChartState extends State { ); } - Widget bottomTitleWidgets( - double value, - TitleMeta meta, - List data, - ) { - const style = TextStyle( - fontWeight: FontWeight.bold, - fontSize: 16, - ); - Widget text; - text = Text( - data[value.toInt()].getTime(context), - style: style, - ); - + Widget bottomTitleWidgets({ + required double value, + required TitleMeta meta, + required List forecast, + required WeatherData data, + }) { + final weekday = forecast[value.toInt()].getWeekDay(context); return SideTitleWidget( fitInside: SideTitleFitInsideData.fromTitleMeta(meta), axisSide: meta.axisSide, - child: text, + child: Column( + children: [ + Text( + forecast[value.toInt()].getTime(context), + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 16, + ), + ), + Text( + weekday == data.getWeekDay(context) ? context.l10n.today : weekday, + style: const TextStyle( + fontWeight: FontWeight.w400, + fontSize: 10, + ), + ), + ], + ), ); } - LineChartData mainData(List forecast) { + LineChartData mainData({ + required List forecast, + required WeatherData data, + }) { final outlineColor = context.theme.colorScheme.onSurface.withOpacity(0.2); return LineChartData( @@ -181,10 +194,14 @@ class _TodayChartState extends State { bottomTitles: AxisTitles( sideTitles: SideTitles( showTitles: true, - reservedSize: 35, + reservedSize: 55, interval: 1, - getTitlesWidget: (value, meta) => - bottomTitleWidgets(value, meta, forecast), + getTitlesWidget: (value, meta) => bottomTitleWidgets( + value: value, + meta: meta, + forecast: forecast, + data: data, + ), ), ), leftTitles: const AxisTitles( From ad3ed941fb5bd3f62511ce91400b22cc0bf0ed03 Mon Sep 17 00:00:00 2001 From: Feichtmeier Date: Sun, 28 Apr 2024 16:53:05 +0200 Subject: [PATCH 2/2] Better names --- .../{forecast_chart.dart => daily_bar_chart.dart} | 4 ++-- .../{today_chart.dart => hourly_line_chart.dart} | 12 ++++++------ .../weather/view/{today_tile.dart => now_tile.dart} | 4 ++-- lib/src/weather/view/weather_page.dart | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) rename lib/src/weather/view/{forecast_chart.dart => daily_bar_chart.dart} (98%) rename lib/src/weather/view/{today_chart.dart => hourly_line_chart.dart} (96%) rename lib/src/weather/view/{today_tile.dart => now_tile.dart} (98%) diff --git a/lib/src/weather/view/forecast_chart.dart b/lib/src/weather/view/daily_bar_chart.dart similarity index 98% rename from lib/src/weather/view/forecast_chart.dart rename to lib/src/weather/view/daily_bar_chart.dart index 7883d54..ef367b8 100644 --- a/lib/src/weather/view/forecast_chart.dart +++ b/lib/src/weather/view/daily_bar_chart.dart @@ -13,8 +13,8 @@ import '../weather_data_x.dart'; import '../weather_model.dart'; import 'error_view.dart'; -class ForeCastChart extends StatelessWidget with WatchItMixin { - const ForeCastChart({super.key}); +class DailyBarChart extends StatelessWidget with WatchItMixin { + const DailyBarChart({super.key}); @override Widget build(BuildContext context) { diff --git a/lib/src/weather/view/today_chart.dart b/lib/src/weather/view/hourly_line_chart.dart similarity index 96% rename from lib/src/weather/view/today_chart.dart rename to lib/src/weather/view/hourly_line_chart.dart index 4b24d72..cb53bfd 100644 --- a/lib/src/weather/view/today_chart.dart +++ b/lib/src/weather/view/hourly_line_chart.dart @@ -11,16 +11,16 @@ import '../../l10n/l10n.dart'; import '../weather_data_x.dart'; import '../weather_model.dart'; import 'error_view.dart'; -import 'today_tile.dart'; +import 'now_tile.dart'; -class TodayChart extends StatefulWidget with WatchItStatefulWidgetMixin { - const TodayChart({super.key}); +class HourlyLineChart extends StatefulWidget with WatchItStatefulWidgetMixin { + const HourlyLineChart({super.key}); @override - State createState() => _TodayChartState(); + State createState() => _HourlyLineChartState(); } -class _TodayChartState extends State { +class _HourlyLineChartState extends State { late ScrollController _scrollController; List gradientColors = [ @@ -115,7 +115,7 @@ class _TodayChartState extends State { ), ), if (data != null) - TodayTile( + NowTile( data: data, fontSize: 20, cityName: cityName, diff --git a/lib/src/weather/view/today_tile.dart b/lib/src/weather/view/now_tile.dart similarity index 98% rename from lib/src/weather/view/today_tile.dart rename to lib/src/weather/view/now_tile.dart index 41ea68f..0228802 100644 --- a/lib/src/weather/view/today_tile.dart +++ b/lib/src/weather/view/now_tile.dart @@ -9,7 +9,7 @@ import '../../l10n/l10n.dart'; import '../theme_x.dart'; import '../weather_data_x.dart'; -class TodayTile extends StatelessWidget { +class NowTile extends StatelessWidget { final WeatherData data; final String? cityName; final double fontSize; @@ -17,7 +17,7 @@ class TodayTile extends StatelessWidget { final String? time; final BorderRadiusGeometry? borderRadius; - const TodayTile({ + const NowTile({ super.key, required this.data, this.cityName, diff --git a/lib/src/weather/view/weather_page.dart b/lib/src/weather/view/weather_page.dart index cf404db..2a85eec 100644 --- a/lib/src/weather/view/weather_page.dart +++ b/lib/src/weather/view/weather_page.dart @@ -6,8 +6,8 @@ import '../../../constants.dart'; import '../../app/app_model.dart'; import '../../app/side_bar.dart'; import '../../l10n/l10n.dart'; -import 'forecast_chart.dart'; -import 'today_chart.dart'; +import 'daily_bar_chart.dart'; +import 'hourly_line_chart.dart'; class WeatherPage extends StatelessWidget with WatchItMixin { const WeatherPage({super.key, this.showDrawer = false}); @@ -59,7 +59,7 @@ class WeatherPage extends StatelessWidget with WatchItMixin { ), ), ), - body: showToday ? const TodayChart() : const ForeCastChart(), + body: showToday ? const HourlyLineChart() : const DailyBarChart(), ), ); }