0

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?

zey
  • 177
  • 2
  • 15

1 Answers1

2

Your future function :

Future<void> func() async {}

Add timeout listener :

func().timeout(const Duration (seconds:5),onTimeout : () {
  // move to the page with warning message
});
manhtuan21
  • 2,388
  • 2
  • 10
  • 24