Skip to content

fix for crash when toggling loading state immediately from initState #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/declarative_refresh_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,21 @@ class _DeclarativeRefreshIndicatorState
super.initState();
// If the indicator should be shown initially, show it.
WidgetsBinding.instance!.addPostFrameCallback((_) {
if (widget.refreshing) _show();
if (widget.refreshing && !_showing)
_show();
else if (!widget.refreshing && _showing) _hide();
});
}

@override
void didUpdateWidget(DeclarativeRefreshIndicator oldWidget) {
super.didUpdateWidget(oldWidget);
// If the [refreshing] field has not changed, do nothing.
if (oldWidget.refreshing == widget.refreshing) return;
// Otherwise, update the indicator accordingly.
super.didUpdateWidget(oldWidget);
if (widget.refreshing) {
// The indicator may have been shown already, if it was shown
// interactively. If it hasn't, show it now.
if (!_showing) _show();
} else {
_hide();
if (_showing) _hide();
}
}

Expand All @@ -162,7 +161,7 @@ class _DeclarativeRefreshIndicatorState
// The completer should not exist at this point.
// It's created here, and must complete before this callback can be
// called again.
assert(_completer == null);
assert(_completer == null, 'The completer should not exist');

// Create the completer and use it.
final completer = Completer<void>();
Expand Down