Member-only story

Do not use BuildContexts across async gaps in flutter

Syed Abdul Basit
4 min readApr 18, 2023

--

After upgrading flutter then the lint is also updated to lint 2.0 and when we use context across async then it give us a warning

Your editor will starts complaining about situation like this:

Because flutter’s build process is 100% synchronous. You were breaking the rule.
So what’s the deal here? The issue is that after an asynchronous gap, your widget BuildContext could be a ticking time bomb waiting to explode the screen when you touch it.

The only safe way to build your widget is to avoid asynchronous usage of build context.

Consider below situation where button submits a form using any state-management and then pops the current screen.

--

--

Responses (2)