Skip to content

Commit 6321a7c

Browse files
committed
Mention Streams
fixes #4310
1 parent 86676dd commit 6321a7c

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

website/docs/3.0_migration.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,32 +135,33 @@ Before, Riverpod was inconsistent in how it filtered updates to providers.
135135
Some providers used `==` to filter updates, while others used `identical`.
136136
In Riverpod 3.0, [all providers now use `==` to filter updates](./whats_new.mdx#all-updateshouldnotify-now-use-).
137137

138-
This generally shouldn't change anything in your code. But if you need to,
139-
you can override `Notifier.updateShouldNotify` to customize the behavior.
138+
The most likely way for you to be impacted by this change is when using
139+
[StreamProvider]/[StreamNotifier], as now stream values will be filtered by `==`.
140+
If you need to, you can override `Notifier.updateShouldNotify` to customize the behavior.
140141

141142
<AutoSnippet
142143
language="dart"
143144
codegen={`
144145
@riverpod
145146
class TodoList extends _$TodoList {
146147
@override
147-
List<Todo> build() => [];
148+
Stream<Todo> build() => Stream(...);
148149
149150
@override
150-
bool updateShouldNotify(List<Todo> previous, List<Todo> next) {
151+
bool updateShouldNotify(AsyncValue<Todo> previous, AsyncValue<Todo> next) {
151152
// Custom implementation
152153
return true;
153154
}
154155
}
155156
`}
156157

157158
raw={`
158-
class TodoList extends Notifier<List<Todo>> {
159+
class TodoList extends StreamNotifier<Todo> {
159160
@override
160-
List<Todo> build() => [];
161+
Stream<Todo> build() => Stream(...);
161162
162163
@override
163-
bool updateShouldNotify(List<Todo> previous, List<Todo> next) {
164+
bool updateShouldNotify(AsyncValue<Todo> previous, AsyncValue<Todo> next) {
164165
// Custom implementation
165166
return true;
166167
}
@@ -376,6 +377,7 @@ if (value.error is NotFoundException) {
376377

377378
[TickerMode]: https://api.flutter.dev/flutter/widgets/TickerMode-class.html
378379
[StreamProvider]: https://pub.dev/documentation/flutter_riverpod/latest/flutter_riverpod/StreamProvider-class.html
380+
[StreamNotifier]: https://pub.dev/documentation/flutter_riverpod/latest/flutter_riverpod/StreamNotifier-class.html
379381
[StreamNotifierProvider]: https://pub.dev/documentation/flutter_riverpod/latest/flutter_riverpod/StreamNotifierProvider.html
380382
[ProviderObserver]: https://pub.dev/documentation/flutter_riverpod/latest/flutter_riverpod/ProviderObserver-class.html
381383
[ProviderContainer]: https://pub.dev/documentation/flutter_riverpod/latest/flutter_riverpod/ProviderContainer-class.html

website/docs/whats_new.mdx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ This can impact you in a few ways:
577577
- If you have a large data class that overrides `==`, you may see a small
578578
performance impact.
579579

580+
The most common case where you will be impacted is when using [StreamProvider]/[StreamNotifier],
581+
as events of the stream are now filtered using `==`.
582+
580583
If you are impacted by those changes, you can override `updateShouldNotify` to
581584
use a custom implementation:
582585

@@ -586,23 +589,23 @@ use a custom implementation:
586589
@riverpod
587590
class TodoList extends _$TodoList {
588591
@override
589-
List<Todo> build() => [];
592+
Stream<Todo> build() => Stream(...);
590593
591594
@override
592-
bool updateShouldNotify(List<Todo> previous, List<Todo> next) {
595+
bool updateShouldNotify(AsyncValue<Todo> previous, AsyncValue<Todo> next) {
593596
// Custom implementation
594597
return true;
595598
}
596599
}
597600
`}
598601

599602
raw={`
600-
class TodoList extends Notifier<List<Todo>> {
603+
class TodoList extends StreamNotifier<Todo> {
601604
@override
602-
List<Todo> build() => [];
605+
Stream<Todo> build() => Stream(...);
603606
604607
@override
605-
bool updateShouldNotify(List<Todo> previous, List<Todo> next) {
608+
bool updateShouldNotify(AsyncValue<Todo> previous, AsyncValue<Todo> next) {
606609
// Custom implementation
607610
return true;
608611
}
@@ -1386,4 +1389,6 @@ regarding combining multiple "sources of truth" in a single provider.
13861389
[ProviderObserver]: https://pub.dev/documentation/flutter_riverpod/latest/flutter_riverpod/ProviderObserver-class.html
13871390
[WidgetTester.container]: https://pub.dev/documentation/flutter_riverpod/latest/flutter_riverpod/RiverpodWidgetTesterX/container.html
13881391
[SyncProviderTransformerMixin]: https://pub.dev/documentation/riverpod/3.0.0-dev.18/misc/SyncProviderTransformerMixin-mixin.html
1389-
[ProviderListenable]: https://pub.dev/documentation/riverpod/3.0.0-dev.18/misc/ProviderListenable-class.html
1392+
[ProviderListenable]: https://pub.dev/documentation/riverpod/3.0.0-dev.18/misc/ProviderListenable-class.html
1393+
[StreamProvider]: https://pub.dev/documentation/flutter_riverpod/latest/flutter_riverpod/StreamProvider-class.html
1394+
[StreamNotifier]: https://pub.dev/documentation/flutter_riverpod/latest/flutter_riverpod/StreamNotifier-class.html

0 commit comments

Comments
 (0)