From 0165a4bad5d24f24443d4f12f598f2a82e6ae7a4 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 20 Jul 2022 17:38:32 +1000 Subject: [PATCH] Bug fix for refreshable state - Prevent setstate if widget is no longer mounted --- lib/widget/refreshable_state.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/widget/refreshable_state.dart b/lib/widget/refreshable_state.dart index 3ea9e5d9..8af4b0ae 100644 --- a/lib/widget/refreshable_state.dart +++ b/lib/widget/refreshable_state.dart @@ -88,8 +88,10 @@ abstract class RefreshableState extends State with return; } + // Refresh the widget - handler for custom request() method Future refresh(BuildContext context) async { + // Escape if the widget is no longer loaded if (!mounted) { return; } @@ -100,6 +102,11 @@ abstract class RefreshableState extends State with await request(context); + // Escape if the widget is no longer loaded + if (!mounted) { + return; + } + setState(() { loading = false; });