Skip to content

Commit 2cc27fb

Browse files
committed
Improve today chart
1 parent ea01e93 commit 2cc27fb

File tree

5 files changed

+151
-306
lines changed

5 files changed

+151
-306
lines changed

lib/src/weather/view/forecast_chart.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import 'package:flutter/cupertino.dart';
44
import 'package:flutter/material.dart';
55
import 'package:flutter/widgets.dart';
66
import 'package:open_weather_client/models/weather_data.dart';
7+
import 'package:watch_it/watch_it.dart';
78
import 'package:yaru/yaru.dart';
89

9-
import '../../build_context_x.dart';
1010
import '../../../constants.dart';
11+
import '../../build_context_x.dart';
1112
import '../weather_data_x.dart';
13+
import '../weather_model.dart';
1214

13-
class ForeCastChart extends StatelessWidget {
14-
const ForeCastChart({super.key, required this.data});
15-
16-
final List<WeatherData> data;
15+
class ForeCastChart extends StatelessWidget with WatchItMixin {
16+
const ForeCastChart({super.key});
1717

1818
@override
1919
Widget build(BuildContext context) {
20+
final data =
21+
watchPropertyValue((WeatherModel m) => m.notTodayForecastDaily);
2022
return Center(
2123
child: Container(
2224
margin: kPagePadding,
@@ -32,9 +34,9 @@ class ForeCastChart extends StatelessWidget {
3234
child: BarChart(
3335
BarChartData(
3436
baselineY: 0,
35-
titlesData: getTitlesData(context),
37+
titlesData: getTitlesData(context, data),
3638
borderData: borderData,
37-
barGroups: barGroups,
39+
barGroups: getBarGroups(data),
3840
gridData: const FlGridData(show: false),
3941
alignment: BarChartAlignment.spaceAround,
4042
maxY: data.map((e) => e.temperature.tempMax).max,
@@ -46,7 +48,8 @@ class ForeCastChart extends StatelessWidget {
4648
);
4749
}
4850

49-
FlTitlesData getTitlesData(BuildContext context) => FlTitlesData(
51+
FlTitlesData getTitlesData(BuildContext context, List<WeatherData> data) =>
52+
FlTitlesData(
5053
show: true,
5154
bottomTitles: AxisTitles(
5255
sideTitles: SideTitles(
@@ -142,7 +145,8 @@ class ForeCastChart extends StatelessWidget {
142145
end: Alignment.bottomCenter,
143146
);
144147

145-
List<BarChartGroupData> get barGroups => data.mapIndexed(
148+
List<BarChartGroupData> getBarGroups(List<WeatherData> data) =>
149+
data.mapIndexed(
146150
(i, e) {
147151
return BarChartGroupData(
148152
x: i,

lib/src/weather/view/forecast_tile.dart

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)