diff --git a/lib/src/weather/view/today_chart.dart b/lib/src/weather/view/today_chart.dart index dba5fed..4bcf81b 100644 --- a/lib/src/weather/view/today_chart.dart +++ b/lib/src/weather/view/today_chart.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:fl_chart/fl_chart.dart'; import 'package:flutter/material.dart'; import 'package:open_weather_client/models/weather_data.dart'; @@ -40,7 +41,8 @@ class _TodayChartState extends State { @override Widget build(BuildContext context) { - final forecast = watchPropertyValue((WeatherModel m) => m.fiveDaysForCast); + final forecast = + watchPropertyValue((WeatherModel m) => m.notTodayFullForecast); final mq = context.mq; final cityName = watchPropertyValue((WeatherModel m) => m.lastLocation); @@ -59,7 +61,7 @@ class _TodayChartState extends State { ), child: error != null ? ErrorView(error: error) - : forecast == null || data == null + : data == null ? Center( child: YaruCircularProgressIndicator( color: context.theme.colorScheme.onSurface, @@ -71,7 +73,7 @@ class _TodayChartState extends State { padding: EdgeInsets.only(top: mq.size.height / 3), scrollDirection: Axis.horizontal, child: SizedBox( - width: forecast.length * 50, + width: forecast.length * 100, height: 400, child: LineChart( mainData(forecast), @@ -137,38 +139,13 @@ class _TodayChartState extends State { ); return SideTitleWidget( + fitInside: SideTitleFitInsideData.fromTitleMeta(meta), axisSide: meta.axisSide, child: text, ); } - Widget leftTitleWidgets(double value, TitleMeta meta) { - const style = TextStyle( - fontWeight: FontWeight.bold, - fontSize: 15, - ); - String text; - switch (value.toInt()) { - case 1: - text = '10K'; - break; - case 3: - text = '30k'; - break; - case 5: - text = '50k'; - break; - default: - return Container(); - } - - return Padding( - padding: const EdgeInsets.all(8.0), - child: Text(text, style: style, textAlign: TextAlign.left), - ); - } - - LineChartData mainData(List data) { + LineChartData mainData(List forecast) { final outlineColor = context.theme.colorScheme.onSurface.withOpacity(0.2); return LineChartData( @@ -207,14 +184,12 @@ class _TodayChartState extends State { reservedSize: 35, interval: 1, getTitlesWidget: (value, meta) => - bottomTitleWidgets(value, meta, data), + bottomTitleWidgets(value, meta, forecast), ), ), - leftTitles: AxisTitles( + leftTitles: const AxisTitles( sideTitles: SideTitles( showTitles: false, - interval: 1, - getTitlesWidget: leftTitleWidgets, reservedSize: 0, ), ), @@ -226,20 +201,19 @@ class _TodayChartState extends State { ), ), minX: 0, - maxX: 11, - minY: 0, - maxY: 6, + maxX: (forecast.length - 1).toDouble(), + minY: forecast.map((e) => e.temperature.currentTemperature).min, + maxY: forecast.map((e) => e.temperature.currentTemperature).max, lineBarsData: [ LineChartBarData( - spots: const [ - FlSpot(0, 3), - FlSpot(2.6, 2), - FlSpot(4.9, 5), - FlSpot(6.8, 3.1), - FlSpot(8, 4), - FlSpot(9.5, 3), - FlSpot(11, 4), - ], + spots: forecast + .mapIndexed( + (i, e) => FlSpot( + i.toDouble(), + e.temperature.currentTemperature, + ), + ) + .toList(), isCurved: true, gradient: LinearGradient( colors: gradientColors,