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.
            Asked
            
        
        
            Active
            
        
            Viewed 175 times
        
    -1
            
            
        - 
                    Does this answer your question? [flutter run function every x amount of seconds](https://stackoverflow.com/questions/52569602/flutter-run-function-every-x-amount-of-seconds) – Sparko Sol Nov 29 '22 at 06:14
 
3 Answers
0
            
            
        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.
        Gwhyyy
        
- 7,554
 - 3
 - 8
 - 35
 
0
            
            
        This work's for me :smile:
Timer.periodic(Duration(milliseconds: 2200), 
 
(timer) {
   
 'Your Method'
     
 debugPrint('Timer 1 sec ${timer.tick.toString()}');
    
});
        MrShakila
        
- 874
 - 1
 - 4
 - 19
 
        Umesh Rajput
        
- 218
 - 1
 - 11
 
0
            
            
        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
        Sparko Sol
        
- 651
 - 1
 - 9
 
        MrShakila
        
- 874
 - 1
 - 4
 - 19