You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How are we supposed to initialize AsyncNotifiers for tests? It's discouraged to mock notifiers according to the docs. I tried it anyway and got errors that I couldn't figure out how to fix. Now I'm trying to set the values of the notifiers before running the tests and Flutter clears them for some reason.
I thought maybe it had something to do with being outside of the pump widget function, so I tried passing a callback to the TestWidget that gets called inside of a postFrameCallback in its initState. In that callback, it would initialize these notifiers for me. This works, but as soon as the widget builds again, the values are cleared.
The text was updated successfully, but these errors were encountered:
It is marked as async, which makes the initialisation, well, async. So you're effectively setting the state to 7 before it is initialised to 5.
Essentially you're setting the state during AsyncLoading.
Describe the bug
Provider state is lost during widget test even though it's keep alive
To Reproduce
Test code:
TestWidget
TestProvider
This will print the following:
Expected behavior
Should print:
How are we supposed to initialize AsyncNotifiers for tests? It's discouraged to mock notifiers according to the docs. I tried it anyway and got errors that I couldn't figure out how to fix. Now I'm trying to set the values of the notifiers before running the tests and Flutter clears them for some reason.
I thought maybe it had something to do with being outside of the pump widget function, so I tried passing a callback to the TestWidget that gets called inside of a postFrameCallback in its initState. In that callback, it would initialize these notifiers for me. This works, but as soon as the widget builds again, the values are cleared.
The text was updated successfully, but these errors were encountered: