fingolfin
fingolfin

Reputation: 19

How to make a function that makes a request every second in flutter

I have a function and I want to request this function again every second. How can I do that?

For example

getMessage(){}

I want to send a request to this function every second and see if there are new messages. How can I do that?

Upvotes: 1

Views: 584

Answers (1)

Valentin Vignal
Valentin Vignal

Reputation: 8202

You can use Timer.periodic for that:

Timer.periodic(
  const Duration(seconds: 1), 
  (timer) => getMessage(),
);

Upvotes: 2

Related Questions