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
If I have no await delay in between setting _loading to true and false, the component remains showing the loading spinner indefinitely. If I have a very short delay instead (eg 1-10 ms), the component crashes with:
======== Exception caught by widgets library =======================================================
The following assertion was thrown building _BodyBuilder:
Hide called, but not showing!
'package:declarative_refresh_indicator/declarative_refresh_indicator.dart':
Failed assertion: line 122 pos 12: '_showing'
Example:
@overridevoidinitState() {
super.initState();
_refresh();
}
void_refresh() async {
setState(() => _loading =true);
//wait anything under ~500ms, or have no `await` at allawaitFuture<void>.delayed(Duration(milliseconds:1));
if (mounted) setState(() => _loading =false);
}
This occurs if _refresh is called immediately from initState.
The text was updated successfully, but these errors were encountered:
The problem here, as you may have identified, is that setState is being called before the internal post-frame callback that initialises the widget is executed. This results in a race condition where didUpdateWidget is being called with refreshing = false before the post-frame callback that shows the indicator does its job.
setState should not be called in initState. You can call _refresh for the first time in a post-frame callback as well. I will fix this in the example.
Is this still an issue when setState is not called in initState?
Hi, thanks for the library!
If I have no
await
delay in between setting _loading to true and false, the component remains showing the loading spinner indefinitely. If I have a very short delay instead (eg 1-10 ms), the component crashes with:Example:
This occurs if
_refresh
is called immediately frominitState
.The text was updated successfully, but these errors were encountered: