skip to Main Content

Whenever my home page was reloaded my data was updated but I want to reflect data instantly.
That’s why I need a method that can refresh my page or method after every 1 second(flutter).
pls, help me.

3

Answers


  1. Chosen as BEST ANSWER

    This work's for me :smile:

    Timer.periodic(Duration(milliseconds: 2200), 
     
    (timer) {
       
     'Your Method'
         
     debugPrint('Timer 1 sec ${timer.tick.toString()}');
        
    });
    

  2. You can use the Timer.periodic to run a method every Duration you specify and using StatefulWidgetn you can run it in initState like this:

      @override
          void initState() {
            Timer.periodic(Duration(seconds: 1), (timer) {
              print("this will execute every second");
            });
        
            super.initState();
          }
    

    change the print with your method.

    Login or Signup to reply.
  3. in Your init state call the Timer like this

     @override
          void initState() {
            new Timer.periodic(Duration(seconds: 1), (Timer t) => YourMethod());//api call 
        
            super.initState();
          }
    

    this will update your full screen

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search