From 1e7dac27e234a8fc61f41bfb6157091b6b5fd50b Mon Sep 17 00:00:00 2001 From: rockgecko-development Date: Fri, 22 Oct 2021 11:15:03 +1100 Subject: [PATCH] fix for crash when toggling loading state immediately from initState --- lib/declarative_refresh_indicator.dart | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/declarative_refresh_indicator.dart b/lib/declarative_refresh_indicator.dart index 6569117..3f1c48b 100644 --- a/lib/declarative_refresh_indicator.dart +++ b/lib/declarative_refresh_indicator.dart @@ -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(); } } @@ -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();