Skip to content

Commit dbbec5f

Browse files
Fix setState() called after dispose() in UncontrolledProviderScope
Adds a mounted check before calling setState() in the frame callback scheduled by UncontrolledProviderScope.build(). This prevents the error when ProviderScope instances are used in scrollable lists and get disposed while frame callbacks are still pending. Fixes #4661 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent e35c43c commit dbbec5f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/flutter_riverpod/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased fix
2+
3+
- Fixed `setState() called after dispose()` error in `UncontrolledProviderScope` when used in scrollable lists (thanks to @itsatifsiddiqui)
4+
15
## 3.2.1 - 2026-02-03
26

37
- Fixed a bug where resuming a paused provider could cause it to never

packages/flutter_riverpod/lib/src/core/provider_scope.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@ To fix this problem, you have one of two solutions:
362362
/// This is for scoped providers to correctly update without causing a
363363
/// markNeedsBuild error.
364364
WidgetsBinding.instance.scheduleFrameCallback(scheduleNewFrame: false, (_) {
365-
setState(() {});
365+
if (mounted) {
366+
setState(() {});
367+
}
366368
});
367369

368370
return _UncontrolledProviderScope(

0 commit comments

Comments
 (0)