title: Fetch Api Data Automatically with Interval in Flutter
body: <p>On my flutter application I am trying to show updating data. I am successful in getting data from weather api manually. But I need to constantly grab data every 5 seconds. So it should be updated automatically. Here is my code in Flutter :</p>
  
  <pre><code>class MyApp extends StatelessWidget {
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Sakarya Hava',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: Text('Sakarya Hava'),
          ),
          body: Center(
            child: FutureBuilder&lt;SakaryaAir&gt;(
              future: getSakaryaAir(), //sets the getSakaryaAir method as the expected Future
              builder: (context, snapshot) {
                if (snapshot.hasData) { //checks if the response returns valid data
                  return Center(
                    child: Column(
                      children: &lt;Widget&gt;[
                        Text("${snapshot.data.temp}"), //displays the temperature
                        SizedBox(
                          height: 10.0,
                        ),
                        Text(" - ${snapshot.data.humidity}"), //displays the humidity
                      ],
                    ),
                  );
                } else if (snapshot.hasError) { //checks if the response throws an error
                  return Text("${snapshot.error}");
                }
                return CircularProgressIndicator();
              },
            ),
          ),
        ),
      );
    }
  
  
    Future&lt;SakaryaAir&gt; getSakaryaAir() async {
      String url = 'http://api.openweathermap.org/data/2.5/weather?id=740352&amp;APPID=6ccf09034c9f8b587c47133a646f0e8a';
      final response =
      await http.get(url, headers: {"Accept": "application/json"});
  
  
      if (response.statusCode == 200) {
        return SakaryaAir.fromJson(json.decode(response.body));
      } else {
        throw Exception('Failed to load post');
      }
    }
  }
  </code></pre>
  
  <p>I found such a snippet to benefit from :</p>
  
  <pre><code>// runs every 5 second
  Timer.periodic(new Duration(seconds: 5), (timer) {
     debugPrint(timer.tick);
  });
  </code></pre>
  
  <p>Probably I need to wrap and call FutureBuilder with this snippet but I was not able to understand how to do it. </p>