Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: change selector example from tuple to records #855

Merged
merged 3 commits into from
Jan 13, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions packages/provider/lib/src/selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,37 @@ class _Selector0State<T> extends SingleChildState<Selector0<T>> {
/// As such, it `selector` should return either a collection ([List]/[Map]/[Set]/[Iterable])
/// or a class that override `==`.
///
/// To select multiple values without having to write a class that implements `==`,
/// the easiest solution is to use a "Tuple" from [tuple](https://pub.dev/packages/tuple):
/// Here's an example:
///
/// ```dart
/// Selector<Foo, Tuple2<Bar, Baz>>(
/// selector: (_, foo) => Tuple2(foo.bar, foo.baz),
/// Example 1:
///
///```dart
/// Selector<Foo, Bar>(
/// selector: (_, foo) => foo.bar, // will rebuild only when `bar` changes
/// builder: (_, data, __) {
/// return Text('${data.item1} ${data.item2}');
/// return Text('${data.item}');
/// }
/// )
///```
///In this example `builder` will be called only when `foo.bar` changes.
///
/// Example 2:
///
///To select multiple values without having to write a class that implements `==`,
///the easiest solution is to use "Records," available from Dart version 3.0.
///For more information on Records, refer to the [records](https://dart.dev/language/records).
rrousselGit marked this conversation as resolved.
Show resolved Hide resolved
///
/// ```dart
/// Selector<Foo, ({String item1, String item2})>(
/// selector: (_, foo) => (item1: foo.item1, item2: foo.item2),
/// builder: (_, data, __) {
/// return Text('${data.item1} ${data.item2}');
/// },
/// );
/// ```
///
/// In that example, `builder` will be called again only if `foo.bar` or
/// `foo.baz` changes.
/// In this example, `builder` will be called again only if `foo.item1` or
/// `foo.item2` changes.
///
/// For generic usage information, see [Consumer].
/// {@endtemplate}
Expand Down