Is it possible to assign a double value as a sleep value in Dart? for example:sleep(Duration(seconds: 1.6));
Asked
Active
Viewed 851 times
-1

blurryface
- 45
- 2
- 7
-
You should never use `sleep` in Dart. Use instead a `Timer`: https://api.dart.dev/stable/2.12.2/dart-async/Timer/Timer.html – julemand101 Mar 24 '21 at 12:44
-
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) – Pavel Shastov Mar 24 '21 at 13:39
-
1Duration only takes integers as values. You could use milliseconds or combining seconds + milliseconds – Mariano Zorrilla Mar 24 '21 at 14:10
3 Answers
1
Duration constructor has a number of optional parameters. You can use the milliseconds one to get 1.6 seconds delay
const Duration(milliseconds: 1600)

Pavel Shastov
- 2,657
- 1
- 18
- 26
-
-
@Janis you are welcome! You can mark this post as an answer then ;) – Pavel Shastov Mar 24 '21 at 19:55
0
Either use Timer class of you can also use Future.delayed() method to do the same.
Below is an example to Future.delayed method :
Future.delayed(const Duration(seconds: 1,milliseconds: 600), () {
// Here you can write your code
});

Sarvesh Dalvi
- 2,260
- 2
- 14
- 30
0
And putting the milliseconds in a parameter:
int Tempo = 1600;

toyota Supra
- 3,181
- 4
- 15
- 19

JcHucDev
- 1
-
1Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 11 '23 at 07:50