Flutter function timeout

1k Views Asked by At

I am using flutter. I wrote a function, if it takes longer than 5 seconds, I want to redirect it to the page with a warning message. Is there an easy way to do this?

1

There are 1 best solutions below

0
On

Your future function :

Future<void> func() async {}

Add timeout listener :

func().timeout(const Duration (seconds:5),onTimeout : () {
  // move to the page with warning message
});