title: How to dynamically update list elements for chart data in Flutter
body: <p>Im trying to create a chart that updates the data by checking every 4 seconds. It checks if the last element of the list is the same as the single element in another list. If not, it will remove the first element and add the newest element in. However this is not updating my graph and it only stays as the initial data. Help please ?</p>
  <pre><code>import 'dart:async';
  import 'package:flutter/foundation.dart';
  import 'package:syncfusion_flutter_charts/charts.dart';
  import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  import 'dart:convert';
  import 'globalvar.dart';
  import 'home_screen.dart';
  import 'chartjsonparse.dart';
  
  class RealHumidityChart extends StatefulWidget {
    @override
    _RealHumidityChartState createState() =&gt; _RealHumidityChartState();
  }
  
  class _RealHumidityChartState extends State&lt;RealHumidityChart&gt; {
  
    List&lt;SensorData&gt; chartData = []; // list for storing the last parsed Json data
    List&lt;SensorData&gt; singleData = [];
    Timer _clearTimer;
  
    Future&lt;String&gt; getChartJsonFromDatabase() async {
      // Sending get(url) request using the http client to retrieve the response.
      var fullResponse = await http.get(fullUrl);
      return fullResponse.body;
      }
  
      Future loadSensorData() async {
        String jsonString = await getChartJsonFromDatabase(); // Deserialization Step #1
        final jsonResponse = json.decode(jsonString); // // Deserialization Step #2
  
        setState(() {
          // Mapping the retrieved json response string and adding the sensor data to the chart data list.
          for (Map i in jsonResponse) {
            chartData.add(
                SensorData.fromJson(i) // Deserialization step #3
            );
          }
        });
    }
  
    Future loadSingleData() async {
      var singleResponse = await http.get(singleUrl);
  
      if (singleResponse.statusCode == 200) {
        final singleJsonResponse = json.decode(singleResponse.body);
  
        for (Map i in singleJsonResponse) {
            singleData.add(
              SensorData.fromJson(i)
            );
            print(&quot;Sucessfully connect singlecode&quot;);
            print(chartData);
          }
      }
    }
  
    @override
    void initState() {
      loadSensorData();
      _clearTimer = Timer.periodic(Duration(seconds: 4), (Timer t) {
        singleData.clear();
        loadSingleData();
        if (chartData.last != singleData.last){
          chartData.removeAt(0);
          chartData.add(singleData.last);
          setState(() {});
        }
         });
      super.initState();
    }
  
    @override
    void dispose() {
      _clearTimer.cancel();
      super.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          backgroundColor: Color(0xff264653),
        ),
        body: SfCartesianChart(
          margin: EdgeInsets.all(15),
          primaryXAxis: CategoryAxis(
            title: AxisTitle(
              text: &quot;Date&quot;,
            )
          ),
          primaryYAxis: NumericAxis(
            // '%' will be append to all Y-axis labels
            labelFormat: '{value} %'
          ),
          //Chart Title
          title: (ChartTitle(text: 'Humidity')),
          //Enable legend
          legend: Legend(isVisible: false),
          //Enable tooltip
          tooltipBehavior: TooltipBehavior(enable: true),
          series: &lt;ChartSeries&lt;SensorData, String&gt;&gt;[
            LineSeries&lt;SensorData, String&gt;(
              name: 'Humidity Chart',
              dataSource: chartData,
              xValueMapper: (SensorData data, _) =&gt; data.date,
              yValueMapper: (SensorData data, _) =&gt; data.sen1,
              //Enable Label Settings
              dataLabelSettings: DataLabelSettings(isVisible: true),
              markerSettings: MarkerSettings(isVisible: true),
            ),
          ]
        ),
      );
    }
  }
  
  class SensorData {
    SensorData(this.date, this.sen1);
  
    String date;
    dynamic sen1;
  
    factory SensorData.fromJson(Map&lt;String, dynamic&gt; parsedJson) {
      return SensorData(
        parsedJson['Date'].toString(),
        parsedJson['Sen1'] as dynamic,
      );
    }
  }
  </code></pre>