1+ import 'package:collection/collection.dart' ;
12import 'package:fl_chart/fl_chart.dart' ;
23import 'package:flutter/material.dart' ;
34import 'package:open_weather_client/models/weather_data.dart' ;
@@ -40,7 +41,8 @@ class _TodayChartState extends State<TodayChart> {
4041
4142 @override
4243 Widget build (BuildContext context) {
43- final forecast = watchPropertyValue ((WeatherModel m) => m.fiveDaysForCast);
44+ final forecast =
45+ watchPropertyValue ((WeatherModel m) => m.notTodayFullForecast);
4446 final mq = context.mq;
4547
4648 final cityName = watchPropertyValue ((WeatherModel m) => m.lastLocation);
@@ -59,7 +61,7 @@ class _TodayChartState extends State<TodayChart> {
5961 ),
6062 child: error != null
6163 ? ErrorView (error: error)
62- : forecast == null || data == null
64+ : data == null
6365 ? Center (
6466 child: YaruCircularProgressIndicator (
6567 color: context.theme.colorScheme.onSurface,
@@ -71,7 +73,7 @@ class _TodayChartState extends State<TodayChart> {
7173 padding: EdgeInsets .only (top: mq.size.height / 3 ),
7274 scrollDirection: Axis .horizontal,
7375 child: SizedBox (
74- width: forecast.length * 50 ,
76+ width: forecast.length * 100 ,
7577 height: 400 ,
7678 child: LineChart (
7779 mainData (forecast),
@@ -137,38 +139,13 @@ class _TodayChartState extends State<TodayChart> {
137139 );
138140
139141 return SideTitleWidget (
142+ fitInside: SideTitleFitInsideData .fromTitleMeta (meta),
140143 axisSide: meta.axisSide,
141144 child: text,
142145 );
143146 }
144147
145- Widget leftTitleWidgets (double value, TitleMeta meta) {
146- const style = TextStyle (
147- fontWeight: FontWeight .bold,
148- fontSize: 15 ,
149- );
150- String text;
151- switch (value.toInt ()) {
152- case 1 :
153- text = '10K' ;
154- break ;
155- case 3 :
156- text = '30k' ;
157- break ;
158- case 5 :
159- text = '50k' ;
160- break ;
161- default :
162- return Container ();
163- }
164-
165- return Padding (
166- padding: const EdgeInsets .all (8.0 ),
167- child: Text (text, style: style, textAlign: TextAlign .left),
168- );
169- }
170-
171- LineChartData mainData (List <WeatherData > data) {
148+ LineChartData mainData (List <WeatherData > forecast) {
172149 final outlineColor = context.theme.colorScheme.onSurface.withOpacity (0.2 );
173150
174151 return LineChartData (
@@ -207,14 +184,12 @@ class _TodayChartState extends State<TodayChart> {
207184 reservedSize: 35 ,
208185 interval: 1 ,
209186 getTitlesWidget: (value, meta) =>
210- bottomTitleWidgets (value, meta, data ),
187+ bottomTitleWidgets (value, meta, forecast ),
211188 ),
212189 ),
213- leftTitles: AxisTitles (
190+ leftTitles: const AxisTitles (
214191 sideTitles: SideTitles (
215192 showTitles: false ,
216- interval: 1 ,
217- getTitlesWidget: leftTitleWidgets,
218193 reservedSize: 0 ,
219194 ),
220195 ),
@@ -226,20 +201,19 @@ class _TodayChartState extends State<TodayChart> {
226201 ),
227202 ),
228203 minX: 0 ,
229- maxX: 11 ,
230- minY: 0 ,
231- maxY: 6 ,
204+ maxX: (forecast.length - 1 ). toDouble () ,
205+ minY: forecast. map ((e) => e.temperature.currentTemperature).min ,
206+ maxY: forecast. map ((e) => e.temperature.currentTemperature).max ,
232207 lineBarsData: [
233208 LineChartBarData (
234- spots: const [
235- FlSpot (0 , 3 ),
236- FlSpot (2.6 , 2 ),
237- FlSpot (4.9 , 5 ),
238- FlSpot (6.8 , 3.1 ),
239- FlSpot (8 , 4 ),
240- FlSpot (9.5 , 3 ),
241- FlSpot (11 , 4 ),
242- ],
209+ spots: forecast
210+ .mapIndexed (
211+ (i, e) => FlSpot (
212+ i.toDouble (),
213+ e.temperature.currentTemperature,
214+ ),
215+ )
216+ .toList (),
243217 isCurved: true ,
244218 gradient: LinearGradient (
245219 colors: gradientColors,
0 commit comments