0

If I am not using getx, is there a way to not check isMounted in Flutter when using async function? Refer to Do not use BuildContexts across async gaps, it looks like we need to check context.mounted every time after async.

React says this is an anti-pattern https://reactjs.org/blog/2015/12/16/ismounted-antipattern.html.

I am curious if there is a better way to resolve this

Hyo
  • 1
  • 2
  • 13

1 Answers1

0

You only need to check isMounted if you await several (>1) async methods that has been called after each other (hence the "across async gaps" phrase).

If you extract the logic, that requires the awaiting, from the UI, then you often can avoid checking isMounted in the Widgets, and instead react appropriately on different types of events.

Robert Sandberg
  • 6,832
  • 2
  • 12
  • 30