Skip to content

Commit

Permalink
Display day in today chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Apr 28, 2024
1 parent 544621c commit 324881c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.
3 changes: 2 additions & 1 deletion lib/src/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion lib/src/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"enterValidApiKey": "Please enter a (valid) API key",
"hourly": "Hourly",
"daily": "Daily",
"now": "Now"
"now": "Now",
"today": "Today"
}
61 changes: 39 additions & 22 deletions lib/src/weather/view/today_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -42,7 +43,7 @@ class _TodayChartState extends State<TodayChart> {
@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);
Expand Down Expand Up @@ -76,7 +77,7 @@ class _TodayChartState extends State<TodayChart> {
width: forecast.length * 100,
height: 400,
child: LineChart(
mainData(forecast),
mainData(forecast: forecast, data: data),
),
),
),
Expand Down Expand Up @@ -123,29 +124,41 @@ class _TodayChartState extends State<TodayChart> {
);
}

Widget bottomTitleWidgets(
double value,
TitleMeta meta,
List<WeatherData> 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<WeatherData> 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<WeatherData> forecast) {
LineChartData mainData({
required List<WeatherData> forecast,
required WeatherData data,
}) {
final outlineColor = context.theme.colorScheme.onSurface.withOpacity(0.2);

return LineChartData(
Expand Down Expand Up @@ -181,10 +194,14 @@ class _TodayChartState extends State<TodayChart> {
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(
Expand Down

0 comments on commit 324881c

Please sign in to comment.