Skip to content

Crash when toggling loading state immediately from initState #1

Closed
@rockgecko-development

Description

@rockgecko-development

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:


======== 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:

@override
  void initState() {
    super.initState();
    _refresh();
  }
 void _refresh() async {
    setState(() => _loading = true);
    //wait anything under ~500ms, or have no `await` at all
    await Future<void>.delayed(Duration(milliseconds: 1));
    if (mounted) setState(() => _loading = false);
  }

This occurs if _refresh is called immediately from initState.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions