title: How Can I Update Image after few seconds in flutter?
body: <p>I'm Building An Flutter Application which requires image changes after a period of time. I thought using while loop with a sleep method inside may solve the problem. But It didn't, Image is only getting change after the loop ends. Application UI also gets froze.</p>
  
  <p>Desired Output: Image should be changed after every 10 seconds.</p>
  
  <p><a href="https://i.stack.imgur.com/zHlyr.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zHlyr.jpg" alt="Image When I clicked On Start BUtton To start The Loop"></a><a href="https://i.stack.imgur.com/GTqMI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GTqMI.jpg" alt="Image After Loop Ends"></a></p>
  
  <p><strong>Image and Button text</strong> is <strong>not Updating</strong> When <strong>Loop is running</strong>, please help me to get the desired output.</p>
  
  <pre><code>
  import 'package:flutter/material.dart';
  
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    // This widget is the root of your application.
    @override
    Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Test(
          ),
        ),
      )
    );
    }}
  class Test extends StatefulWidget {
    @override
    _TestState createState() =&gt; _TestState();
  }
  
  class _TestState extends State&lt;Test&gt; {
    int imgnumber=1;
    int varToCheckButtonPress = 0;
    String BtnTxt = "START";
    void inc(){
      while(imgnumber&lt;10)
        {
          print(imgnumber);
          setState(() {
            sleep(Duration(seconds:5));
            imgnumber++;
          });
        }
    }
    @override
    Widget build(BuildContext context) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: &lt;Widget&gt;[
          Expanded(flex: 1,
            child: Container(
              child: Image.asset('images/'+imgnumber.toString()+'.png'),
              height: 500,
              width:500,
              color: Colors.green,
            ),
          ),
          FlatButton(
            child: Text(BtnTxt),
            onPressed: (){
              if (varToCheckButtonPress == 0) {
                setState(() {
                  BtnTxt = 'PAUSE';
                  varToCheckButtonPress = 1;
                });
              } else if (varToCheckButtonPress == 1) {
                setState(() {
                  BtnTxt = 'RESUME';
                  varToCheckButtonPress = 0;
                });
              }
              inc();
            },
          )
        ],
      );
    }
  }
  </code></pre>