I am getting value from http request within a function ,I need to execute a Function during a time (1 min) , So this function can repeat itself during this time (1 min) to analysis this value from http for every 1 min , can I do this ?
Asked
Active
Viewed 370 times
-1
-
Does this answer your question? [How to run code after some delay in Flutter?](https://stackoverflow.com/questions/49471063/how-to-run-code-after-some-delay-in-flutter) – Sanjay Sharma May 26 '20 at 17:51
-
1@SanjaySharma The OP is asking for a method of periodically running code, not just once after a delay. – Christopher Moore May 26 '20 at 19:50
-
1@ChristopherMoore I think it has the required help. Check [this](https://stackoverflow.com/a/59500175/4788260) – Sanjay Sharma May 26 '20 at 20:04
-
@SanjaySharma That should be added as an answer on **this** question with a link to that answer for credit as that question is not a duplicate. – Christopher Moore May 26 '20 at 20:10
-
@ChristopherMoore yes this should answer my question – Mohamed Alaa May 26 '20 at 21:23
-
An answer on this question should still be accepted or the question should be closed. – Christopher Moore May 26 '20 at 21:24
-
So change [this](https://api.dart.dev/stable/2.8.2/dart-async/Timer/Timer.periodic.html) to [this](https://stackoverflow.com/questions/49471063/how-to-run-code-after-some-delay-in-flutter/59500175#59500175) to accept your answer – Mohamed Alaa May 26 '20 at 21:33
1 Answers
1
You can use Timer.periodic
to periodically run a function with the given time.
You can read more about this here.
Example usage:
Timer.periodic(Duration(seconds: 5), (timer) {
print(DateTime.now());
});

Christopher Moore
- 15,626
- 10
- 42
- 52
-
-
-
I mean that I am using this `stream: Stream.periodic(Duration(seconds: 1)).asyncMap((i) => _value()),` So Can I use Timer.periodic with StreamBuilder to make what I want – Mohamed Alaa May 26 '20 at 17:32
-
@MohamedAlaa I'm confused. Why do you need a `Stream`? I didn't see any info about that in your question. – Christopher Moore May 26 '20 at 17:33
-
Okay I understand what you say sorry if I not clear in my question – Mohamed Alaa May 26 '20 at 17:37
-
@MohamedAlaa If you provide more information I might be able to help you. – Christopher Moore May 26 '20 at 17:39
-