Skip to content

Commit fe2a260

Browse files
authored
## Related Issues fixes #4669 <!-- Update to link the issue that is going to be fixed by this. Unless this concerns documentation, make sure to create an issue first before raising a PR. You do not need to describe what this PR is doing, as this should already be covered by the associated issue. If the linked issue isn't enough, then chances are a new issue is needed. Don't hesitate to create many issues! This can avoid working on something, only to have your PR closed or have to be rewritten due to a disagreement/misunderstanding. --> ## Checklist Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (`[x]`). - [ ] I have updated the `CHANGELOG.md` of the relevant packages. Changelog files must be edited under the form: ```md ## Unreleased fix/major/minor - Description of your change. (thanks to @yourgithubid) ``` - [ ] If this contains new features or behavior changes, I have updated the documentation to match those changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed an issue where resuming a paused provider could fail to notify listeners, ensuring buffered events are processed on resume. * **Tests** * Added regression tests covering provider flush/notification behavior across navigation/resume scenarios. * **Documentation** * Updated changelogs to add an "Unreleased fix" entry and remove duplicated/incorrect bullets for prior releases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent f8734c9 commit fe2a260

File tree

5 files changed

+67
-6
lines changed

5 files changed

+67
-6
lines changed

packages/flutter_riverpod/CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Unreleased fix
2+
3+
- Fixed a bug where resuming a paused provider could cause it to never
4+
notify its listener ever again.
5+
16
## 3.2.0 - 2026-01-17
27

38
- Fix the IDE pausing on "markNeedsBuild" exceptions when checking "pause on all exceptions".
@@ -723,7 +728,6 @@ Riverpod is now stable!
723728
```
724729

725730
That allows providers to implement features that is not shared with other providers.
726-
727731
- `Provider`, `FutureProvider` and `StreamProvider`'s `ref` now have a `state` property,
728732
which represents the currently exposed value. Modifying it will notify the listeners:
729733

@@ -1024,7 +1028,6 @@ Fixed various issues related to scoped providers.
10241028
```
10251029

10261030
That allows providers to implement features that is not shared with other providers.
1027-
10281031
- `Provider`, `FutureProvider` and `StreamProvider`'s `ref` now have a `state` property,
10291032
which represents the currently exposed value. Modifying it will notify the listeners:
10301033

@@ -1498,4 +1501,3 @@ The behavior is the same. Only the syntax changed.
14981501
Initial release
14991502

15001503
<!-- cSpell:ignoreRegExp @\w+ -->
1501-
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import 'dart:async';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_riverpod/flutter_riverpod.dart';
5+
import 'package:flutter_test/flutter_test.dart';
6+
7+
void main() {
8+
testWidgets('flushes the provider', (tester) async {
9+
// Regression test for https://github.com/rrousselGit/riverpod/issues/4669
10+
final dep = NotifierProvider(() => DeferredNotifier<int>((ref, _) => 0));
11+
final provider = Provider((ref) => ref.watch(dep));
12+
13+
await tester.pumpWidget(
14+
ProviderScope(
15+
child: MaterialApp(
16+
routes: {'/settings': (context) => Container()},
17+
home: Consumer(
18+
builder: (context, ref, _) {
19+
final value = ref.watch(provider);
20+
return Text('$value', textDirection: TextDirection.ltr);
21+
},
22+
),
23+
),
24+
),
25+
);
26+
27+
final container = tester.container();
28+
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
29+
30+
unawaited(navigator.pushNamed('/settings'));
31+
await tester.pumpAndSettle();
32+
33+
container.read(dep.notifier).state++;
34+
35+
unawaited(navigator.maybePop());
36+
await tester.pumpAndSettle();
37+
38+
expect(find.text('1'), findsOneWidget);
39+
});
40+
}
41+
42+
class DeferredNotifier<StateT> extends Notifier<StateT> {
43+
DeferredNotifier(this._build);
44+
45+
final StateT Function(Ref ref, DeferredNotifier<StateT> self) _build;
46+
47+
@override
48+
StateT build() {
49+
return _build(ref, this);
50+
}
51+
}

packages/hooks_riverpod/CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Unreleased fix
2+
3+
- Fixed a bug where resuming a paused provider could cause it to never
4+
notify its listener ever again.
5+
16
## 3.2.0 - 2026-01-17
27

38
- Fix the IDE pausing on "markNeedsBuild" exceptions when checking "pause on all exceptions".
@@ -878,7 +883,6 @@ Riverpod is now stable!
878883
```
879884

880885
That allows providers to implement features that is not shared with other providers.
881-
882886
- `Provider`, `FutureProvider` and `StreamProvider`'s `ref` now have a `state` property,
883887
which represents the currently exposed value. Modifying it will notify the listeners:
884888

@@ -1211,7 +1215,6 @@ Fixed various issues related to scoped providers.
12111215
```
12121216

12131217
That allows providers to implement features that is not shared with other providers.
1214-
12151218
- `Provider`, `FutureProvider` and `StreamProvider`'s `ref` now have a `state` property,
12161219
which represents the currently exposed value. Modifying it will notify the listeners:
12171220

@@ -1700,4 +1703,3 @@ The behavior is the same. Only the syntax changed.
17001703
Initial release
17011704

17021705
<!-- cSpell:ignoreRegExp @\w+ -->
1703-

packages/riverpod/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Unreleased fix
2+
3+
- Fixed a bug where resuming a paused provider could cause it to never
4+
notify its listener ever again.
5+
16
## 3.2.0 - 2026-01-17
27

38
- Added missing `weak` flags to `WidgetRef.listen/listenManual`

packages/riverpod/lib/src/core/provider_subscription.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ sealed class ProviderSubscriptionImpl<OutT> extends ProviderSubscription<OutT>
140140
_listenedElement.onSubscriptionResumeOrReactivate(this, () {
141141
final wasPaused = _isPaused;
142142
super.resume();
143+
_listenedElement.flush();
143144

144145
if (wasPaused && !isPaused) {
145146
if (_missedCalled?.data case final event?) {

0 commit comments

Comments
 (0)