title: Flutter - how to update screen with latest api response
body: <p>I want to update the screen whenever I call the API. Right now I have the following</p>
  <pre><code>Future&lt;String&gt; getData() async {
  var response = await http.get(
      Uri.parse('https://www.api_endpoint.com'),
      headers: {
        'Accept':'application/json'
      }
  );
  
  Timer.periodic(Duration(microseconds: 1000), (_) {
    this.setState(() {
      data = json.decode(response.body);
      print(data); //I can see this in the console/logcat
    });
  });
  
  }
  
  @override
  void initState() {
    this.getData();
  }
  </code></pre>
  <p>from the line above <code>print(data);</code> I can see the latest api responses in console/logcat but the screen doesn't update with the new values. I can't get my head around why the latest responses aren't shown on screen when <code>this.setState()</code> is called every second with the Timer... all feedback is welcome. Thanks</p>