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

Documentation update (#1618) #1728

Merged
merged 193 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
193 commits
Select commit Hold shift + click to select a range
c1e9631
Add toggles to enable/disable hooks and code generation (#1618)
rrousselGit Oct 4, 2022
da5bbe5
Upgrade packages
rrousselGit Oct 4, 2022
5b547a4
Add @babel/helper-get-function-arity
rrousselGit Oct 4, 2022
f4205c4
Update version test
rrousselGit Oct 5, 2022
132115e
Move getting_started snippets
rrousselGit Oct 5, 2022
0c3db50
Update all getting_started snippets to use interactive codegen/hooks …
rrousselGit Oct 5, 2022
4fa714b
Fix broken translation links
rrousselGit Oct 5, 2022
64168de
Add "About hooks" page
rrousselGit Oct 5, 2022
ba7a36e
Disable hooks by default
rrousselGit Oct 5, 2022
12e13cb
Add barebone "about codegen" doc
rrousselGit Oct 5, 2022
0fc5a0a
Small refactor of codegen doc
rrousselGit Oct 5, 2022
1613cd1
Redirect to getting_started for codegen usage
rrousselGit Oct 6, 2022
8202650
Small update
rrousselGit Oct 6, 2022
b15afc3
Reorganize sidebar a bit
rrousselGit Oct 6, 2022
9c861e4
Extract snippets to dart files
rrousselGit Oct 6, 2022
c2e3368
deploy branch
rrousselGit Oct 7, 2022
637e38f
Typo
rrousselGit Oct 7, 2022
88b4267
Fix mobile sidebar
rrousselGit Oct 8, 2022
e360043
Merge branch 'master' of https://github.com/rrousselGit/river_pod int…
rrousselGit Oct 8, 2022
f67a9ab
Update docs to match
rrousselGit Oct 8, 2022
d998b2d
Merge branch 'master' of https://github.com/rrousselGit/river_pod int…
rrousselGit Oct 8, 2022
f2dfa93
Update docs
rrousselGit Oct 8, 2022
9980068
Add banner to notify that the current doc page might be out of date (…
rrousselGit Oct 9, 2022
5e6adc9
Remove "what package to install" section as it is covered by docs tog…
rrousselGit Oct 9, 2022
d9b4665
Add introduction page
rrousselGit Oct 9, 2022
4ff0f74
Make docs/providers/future_provider compatible with toggles (#1752)
mansourzaki Oct 10, 2022
5ce6c63
Fixed a typo (#1755)
hamza-imran75 Oct 10, 2022
ea17468
Update copyright year text (#1760)
JAICHANGPARK Oct 12, 2022
f0750fa
Update SEO description
rrousselGit Oct 12, 2022
edbcd1f
Merge branch 'docs-v2' of https://github.com/rrousselGit/river_pod in…
rrousselGit Oct 12, 2022
16057b9
Update initial snippet to use bored API
rrousselGit Oct 12, 2022
ddc4281
Update readme to match
rrousselGit Oct 12, 2022
27cdac8
Fix analysis issues in website snippet
rrousselGit Oct 13, 2022
f0a82a1
Run generator on static folder
rrousselGit Oct 13, 2022
1c9bae9
Clean up roadmap
rrousselGit Oct 13, 2022
95d7f20
Selling points roadmap
rrousselGit Oct 14, 2022
1c3b1d1
Merge branch 'master' of https://github.com/rrousselGit/river_pod int…
rrousselGit Oct 14, 2022
7c17cb8
Remove preview banner
rrousselGit Oct 14, 2022
bb5f1f9
Create a Provider -> Create a network request
rrousselGit Oct 14, 2022
e8aa353
Trim readme from Provider content
rrousselGit Oct 14, 2022
f1d1f06
Add "Riverpod for provider users"
rrousselGit Oct 15, 2022
74ca338
Cover how to convert ProxyProvider
rrousselGit Oct 16, 2022
b07dfed
Fix typo
rrousselGit Oct 26, 2022
df93f42
Update riverpod_for_provider_users.mdx (#1842)
escwxyz Oct 30, 2022
e126080
Fix a typo (#1846)
hamza-imran75 Oct 30, 2022
c6b72ca
Changed the structure of the sentence. (#1847)
hamza-imran75 Oct 30, 2022
4dbba74
Update docs to match deprecated Reader
rrousselGit Nov 16, 2022
ba7b99a
Add codegen snippets for "Provider" Page (#1863)
leehack Nov 27, 2022
b22a871
add immutability documentation (#1690)
TimWhiting Dec 21, 2022
129e62c
add lifecycle documentation (#1689)
TimWhiting Dec 21, 2022
3c6cef5
Add documentation about scoping (#1688)
TimWhiting Dec 21, 2022
ab518c5
Merge branch 'master' of https://github.com/rrousselGit/river_pod int…
rrousselGit Dec 21, 2022
1b082b5
Fix lints
rrousselGit Dec 21, 2022
d8bb9be
Update outdated list
rrousselGit Dec 21, 2022
8f7825d
Fix merge
rrousselGit Dec 21, 2022
f55ee0e
Add gemerated files
rrousselGit Dec 21, 2022
45149ef
Update versions
rrousselGit Dec 21, 2022
0e53266
Pub get in third-party folder
rrousselGit Dec 21, 2022
d5c9ac5
Migrate Korean Documents to docs v2 (#1996)
JAICHANGPARK Jan 8, 2023
3f4afe8
Merge branch 'master' of https://github.com/rrousselGit/river_pod int…
rrousselGit Jan 8, 2023
a304c3d
Update dependencies
rrousselGit Jan 8, 2023
8f3adec
Update generated files
rrousselGit Jan 8, 2023
fd8296d
Bump versions
rrousselGit Jan 8, 2023
165cab4
Update outdated translations
rrousselGit Jan 8, 2023
77e704e
Upgrade annotation version
rrousselGit Jan 8, 2023
a2afccc
Add missing generated files
rrousselGit Jan 8, 2023
91c17ba
Update more versions
rrousselGit Jan 8, 2023
f316392
Typo
rrousselGit Jan 8, 2023
01f66c9
Add missing french translations for v2 docs (#2042)
PapiHack Jan 8, 2023
52885de
Upgrade docusaurus to 2.2.0
rrousselGit Jan 8, 2023
f891bb6
Fr Docs v2 (#2070)
GitGud31 Jan 8, 2023
6207588
Re-add imports
rrousselGit Jan 8, 2023
672936c
Merge branch 'master' of https://github.com/rrousselGit/river_pod int…
rrousselGit Jan 8, 2023
f2eae8e
Merge branch 'master' of https://github.com/rrousselGit/river_pod int…
rrousselGit Jan 8, 2023
699b65d
Merge branch 'master' of https://github.com/rrousselGit/river_pod int…
rrousselGit Jan 9, 2023
b942875
Update concept reading page code examples (#2032)
leehack Jan 10, 2023
9ec6144
Add notifier provider page to docs v2 (#2023)
leehack Jan 10, 2023
d9bdd00
Fix minor typo + (Async)NotifierProvider section translation (#2134)
PapiHack Feb 6, 2023
cef014e
Docs v2 add simplified Chinese translation (#2129)
laiiihz Feb 6, 2023
60164ff
Japanese Translation for docs v2 (#2154)
sj-h4 Feb 14, 2023
97fadb3
hook code snippets in getting started page (#2202)
mboyamike Feb 19, 2023
3955b42
Support codegen/hooks for more snippets (#2224)
mboyamike Feb 27, 2023
5ad1895
Fix typo (#2250)
iDevOrz Mar 3, 2023
ecadeb9
Docs v2: Add hook snippets for the concepts/reading a provider page (…
mboyamike Mar 7, 2023
e6f787e
Add Korean Translation in "why immutability" of docs v2 (#2280)
MinyeongHong Mar 8, 2023
37b74ae
Fix som typos in fr docs-v2 (#2292)
PapiHack Mar 10, 2023
af139d1
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Mar 12, 2023
a130d5a
Install deps
rrousselGit Mar 12, 2023
d3bdf62
Update generated files
rrousselGit Mar 12, 2023
12ff660
Update dart pubspec
rrousselGit Mar 12, 2023
dcb302e
Update flutter pubsepc
rrousselGit Mar 12, 2023
6e6397e
Upgrade min SDK
rrousselGit Mar 12, 2023
f99b90f
Apply dart fix
rrousselGit Mar 12, 2023
019334b
Ignore lints in generated files
rrousselGit Mar 12, 2023
7231ff4
Update generated files
rrousselGit Mar 12, 2023
286bdce
Install json_serializable
rrousselGit Mar 12, 2023
87d80fc
Update outdated json
rrousselGit Mar 12, 2023
716994b
Remove dead files
rrousselGit Mar 12, 2023
a9047dc
Fix versions
rrousselGit Mar 12, 2023
be4d8bd
Update homepage a bit (#2308)
rrousselGit Mar 12, 2023
f65099f
docs: some updates to docs (#2319)
AhmedLSayed9 Mar 13, 2023
8303f2f
docs: extra updates to docs (#2331)
AhmedLSayed9 Mar 16, 2023
5456e7d
docs: v2 fr translations of homepage's new sections and community exa…
PapiHack Mar 20, 2023
77699d7
docs: add one line install command (#2345)
utamori Apr 1, 2023
327a511
docs: code snippets for concepts/combining_providers (#2357)
mboyamike Apr 1, 2023
5b5e842
docs(v2): refactor Chinese translations (#2433)
escwxyz Apr 8, 2023
40d4e5c
Docs v2 (#2486)
mboyamike Apr 24, 2023
a89320d
Docs v2: More consistent use of notifier over state notifier (#2513)
mboyamike May 2, 2023
c22ce14
Update getting_started.mdx (#2519)
kwill39 May 4, 2023
4a74163
Fix mismatching parameter types in code gen example (#2533)
kwill39 May 6, 2023
2c492b7
Show how to enable custom_lint's plugin in Getting Started (#2528)
kwill39 May 10, 2023
d8fa040
Navigate to Introduction instead of Getting Started when clicking Docs
kwill39 May 10, 2023
014a5b9
Emtnion refactors and link to the full list of lints/refactors
rrousselGit May 10, 2023
014724c
Delete lock file
rrousselGit May 12, 2023
1a2083d
Delete dart generator & related dependencies
rrousselGit May 12, 2023
9af7160
Add JS generator variant & run script in "npm run build"
rrousselGit May 12, 2023
0ffc038
FIx build command
rrousselGit May 12, 2023
4c3fa1b
Deleted dead workflow
rrousselGit May 12, 2023
414031f
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit May 12, 2023
35e233b
Fix overrides
rrousselGit May 12, 2023
c772400
Fix version test
rrousselGit May 12, 2023
d36a869
Merge pull request #2555 from rrousselGit/automate-outdated-banner
rrousselGit May 12, 2023
82d9bea
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit May 30, 2023
a4a757c
Update zh_Hans GettingStarted page (#2593)
laiiihz May 30, 2023
6af3f40
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit May 30, 2023
1ba2fa6
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Jun 9, 2023
7c4d998
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Jun 21, 2023
8ffcfe7
docs: Improve the "About Code generation" page to add migration guide…
AhmedLSayed9 Jun 23, 2023
eab58b5
Prefix Future/Stream with async (#2673)
AhmedLSayed9 Jun 26, 2023
01f9733
[docs-v2] Save toogle state (#2683)
CaiJingLong Jul 6, 2023
9320232
Change deprecated terminal command (#2708)
eshfield Jul 10, 2023
8bcabf8
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Jul 10, 2023
5babe46
Move getting_started/hello_world's hooks to getting_started/hello_wor…
rrousselGit Jul 10, 2023
9d1f2c7
Add flutter_hooks as dependency in getting_started
rrousselGit Jul 10, 2023
6a09a92
Fix broken links
rrousselGit Jul 10, 2023
02b03b7
Use newline for install command
rrousselGit Jul 10, 2023
1655032
Format snippets in getting_Started
rrousselGit Jul 10, 2023
483ee4b
Update home snippets to stop using "when" & start using codegen/patterns
rrousselGit Jul 15, 2023
0da6c86
Add discord link
rrousselGit Jul 15, 2023
c616a71
Intro -> Why Riverpod
rrousselGit Jul 15, 2023
fd13c5d
Add why_riverpod to footer
rrousselGit Jul 15, 2023
54d8846
Update intro
rrousselGit Jul 15, 2023
3c793f4
Add Zapp embed and update TODOs app
rrousselGit Jul 15, 2023
98cd604
Update pubspecs in Getting Started to use SDK >=3
rrousselGit Jul 15, 2023
a398e85
Tone change
rrousselGit Jul 15, 2023
c89159a
Tone
rrousselGit Jul 15, 2023
9f17b3b
Bump
rrousselGit Jul 15, 2023
f7500eb
Add versions
rrousselGit Jul 15, 2023
7963838
Most recent migration first
rrousselGit Jul 15, 2023
61cca3b
Mention that code-generation is encouraged
rrousselGit Jul 15, 2023
b3fd21e
Reorder
rrousselGit Jul 15, 2023
442ed6c
Cleanup more
rrousselGit Jul 15, 2023
ebec846
Use tear-off and format
rrousselGit Jul 15, 2023
6ed3eee
Global mention
rrousselGit Jul 15, 2023
4536684
About hooks update
rrousselGit Jul 15, 2023
e4415a3
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Jul 15, 2023
eb3a5d7
Super
rrousselGit Jul 15, 2023
73b978f
Improvements on grammar (#2738)
SakhileMamba Jul 16, 2023
464e053
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Jul 16, 2023
aef6bd7
Update tests
rrousselGit Jul 16, 2023
ae44d2a
Mention zapp
rrousselGit Jul 16, 2023
4cfdd1e
Rename Function-based to Functional (#2737)
AhmedLSayed9 Jul 17, 2023
288f458
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Jul 27, 2023
12f2faf
Add missing override
rrousselGit Jul 27, 2023
fb4d8f8
Rework sidebar (#2740)
rrousselGit Aug 29, 2023
ac48c11
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Aug 29, 2023
0f53b20
Bump dev dependency
rrousselGit Aug 29, 2023
e056800
Update generated code
rrousselGit Aug 29, 2023
c0f4ac7
Update side_effects.mdx (#2868)
nah0y Aug 31, 2023
b0397f6
Fix typo (#2916)
robert-virkus Sep 24, 2023
0c28a2a
Fix. Broken links on .family modifier docs page (#2956)
droidbg Oct 5, 2023
2ac5f71
Add websocket/sync page
rrousselGit Oct 5, 2023
74754b8
Merge branch 'docs-v2' of https://github.com/rrousselGit/riverpod int…
rrousselGit Oct 5, 2023
abf3861
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Oct 5, 2023
83f4819
Sync generated code
rrousselGit Oct 5, 2023
8f90f30
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Oct 5, 2023
8246a7a
Sync riverpod version
rrousselGit Oct 5, 2023
2e6cdd2
Hide wip pages
rrousselGit Oct 5, 2023
1e26c30
Plan docs
rrousselGit Oct 7, 2023
a981767
Fix hash links not working
rrousselGit Oct 9, 2023
d41dc34
Add combining_request page
rrousselGit Oct 9, 2023
16ba344
Add disposal page
rrousselGit Oct 9, 2023
d4cf33c
Restore legacy docs
rrousselGit Oct 9, 2023
fa9453d
Ignore todos in website
rrousselGit Oct 9, 2023
93a4368
Add eager initialization docs
rrousselGit Oct 10, 2023
a8025fa
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Oct 10, 2023
13b8771
Merge branch 'master' of https://github.com/rrousselGit/riverpod into…
rrousselGit Oct 10, 2023
e6cfe9b
Plan "show snackbar" sample
rrousselGit Oct 10, 2023
5eceb2b
Add testing page
rrousselGit Oct 10, 2023
4567a75
Update generated code
rrousselGit Oct 10, 2023
59000f7
Downgrade `test`
rrousselGit Oct 10, 2023
07aac26
Add select page
rrousselGit Oct 11, 2023
0c550d1
Highlight .future usage
rrousselGit Oct 11, 2023
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
Prev Previous commit
Next Next commit
Add combining_request page
  • Loading branch information
rrousselGit committed Oct 9, 2023
commit d41dc342ddb4cc2da1b22afe4d47a24f4bf385ce
145 changes: 125 additions & 20 deletions website/docs/essentials/combining_requests.mdx
Original file line number Diff line number Diff line change
@@ -1,30 +1,135 @@
---
title: Combining requests (WIP)
title: Combining requests
version: 1
---

:::note
This page is a work in progress
import { Link } from "../../src/components/Link";
import { AutoSnippet } from "../../src/components/CodeSnippet";
import functionalRef from "./combining_requests/functional_ref";
import notifierRef from "./combining_requests/notifier_ref";
import watchExample from "./combining_requests/watch_example";
import watchPlacement from "./combining_requests/watch_placement";
import listenExample from "./combining_requests/listen_example";
import readExample from './combining_requests/read_example'

Up till now, we've only seens cases were requests are independent from each
other. But a common use-case is to have to trigger a request based on the
result of another request.

We _could_ be using the <Link documentID="essentials/passing_args" /> mechanism to
do that, by passing the result of a provider as parameter to another a provider.

But this approach has a few downsides:

- This leaks implementation details.
Now, your UI needs to know about all the providers that are used
your other provider.
- Whenever the parameter change, a brand new state will be made.
By passing parameters, there are no way to keep the previous state
when the parameter changes.
- It makes combining requests harder.
- This makes tooling less useful. A devtool wouldn't
know about the relationship between providers.

To improve this, Riverpod offers a different approach to combine requests.

## The basics: Obtaining a "ref"

All possible ways of combining requests have one thing in common:
They are all based on the `Ref` object.

The `Ref` object is an object which all providers have access to.
It grants them access to various life-cycle listeners, but also
various methods to combine providers.

The place where `Ref` can be obtained depends on the type of provider.

In functional providers, the `Ref` is passed as parameter to the
provider's function:

<AutoSnippet {...functionalRef} />

In class variants, the `Ref` is a property of the Notifier class:

<AutoSnippet {...notifierRef} />

## Using ref to read a provider.

## The `ref.watch` method.

Now that we've obtained a `Ref`, we can use it to combine requests.
The main way to do so is by using `ref.watch`.
It is generally recommended to architecture your code such that you
can use `ref.watch` over other options, as it is generally easier to maintain.

The `ref.watch` method takes a provider, and returns its current state.
Then, whenever the listened provider changes, our provider will be
invalidated and rebuilt next frame or on next read.

By using `ref.watch`, your logic becomes both "reactive" and "declarative".
Meaning that your logic will automatically recompute when needed.
And that the update mechanism doesn't rely on side-effects, such as an "on change".
This is similar to how StatelessWidgets behave.

As an example, we could define a provider that listens to the user's location.
Then, we could use this location to fetch the list of restaurants near the user.

<AutoSnippet {...watchExample} />

:::info
When the listened provider changes and our request recomputes, the previous
state is kept until the new request completes.
At the same time, while the request is pending, the "isLoading" and "isReloading"
flags will be set.

This enables UI to either show the previous state, or a loading indicator,
or even both.
:::

- [ ] Mention that some network requests may depend on the result of
other requests. For example, a request to get the list of cities
near the user would depend on a request to get the user's location.
:::caution
It is considered bad practice to call `ref.watch` inside code that is executed
"imperatively". Meaning any code that is possibly not executed during the build
phase of the provider. This includes "listener" callbacks or methods on Notifiers:

<AutoSnippet {...watchPlacement} />
:::

## The `ref.listen`/`listenSelf` methods.

The `ref.listen` method is an alternative to `ref.watch`.
It is similar to your traditional "listen"/"addListener" method. It takes a provider
and a callback, and will invoke said callback whenever the content of the provider
changes.

- [ ] Mention that there are two primary ways to combine requests:
Refactoring your code such thar you can use `ref.watch` instead of `ref.listen`
is generally recommended, as the latter is more error-prone due to its imperative nature.
But `ref.listen` can be helpful to add some quick logic without having to do
significant refactor.

- [ ] `ref.watch` - declarative approach, will automatically recompute the request on change
- [ ] Mention that this is the recommended approach due to simplified error handling
& automatic recomputation.
- [ ] `ref.listen` - imperative approach, will invoke a listener when the result changes.
It is then up to the listener to perform changes, such as maybe calling `ref.state=`.
- [ ] Link Provider migration guide, to showcase how using ref.listen
can be used to migrate ProxyProviders to Riverpod
We could rewrite the `ref.watch` example to use `ref.listen` instead

- [ ] A `ref` is always available when defining a provider:
- it is either passed as parameter to the provider's function
- or it is a property of the Notifier class.
<AutoSnippet {...listenExample} />

- Explain how if an async provider refreshes with ref.watch, its previous state is kept
until the new state is available, but under "isReloading: true".
If the provider rebuildt with ref.invalidate/refresh, then isRefreshing will be true instead.
:::info
It is entirely safe to use `ref.listen` during the build phase of a provider.
If the provider somehow is recomputed, previous listeners will be removed.

Alternatively, you can use the return value of `ref.listen` to remove the listener
manually when you wish.
:::

## The `ref.read` method.

The last option available is `ref.read`.
It is similar to `ref.watch` in that it returns the current state of a provider.
But unlike `ref.watch`, it doesn't listen to the provider.

As such, `ref.read` should be only be used in placed where you can't use
`ref.watch`, such as inside methods of Notifiers.

<AutoSnippet {...readExample} />

:::caution
Be careful when using `ref.read` on a provider as, since it doesn't listen to the
provider, said provider may decide to destroy its state if it isn't listened.
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// ignore_for_file: unused_local_variable

import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'codegen.g.dart';

@riverpod
int other(OtherRef ref) => 0;

/* SNIPPET START */
@riverpod
int example(ExampleRef ref) {
// "Ref" can be used here to read other providers
final otherValue = ref.watch(otherProvider);

return 0;
}
/* SNIPPET END */

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import raw from '!!raw-loader!./raw.dart';
import codegen from '!!raw-loader!./codegen.dart';

export default { raw, codegen };
14 changes: 14 additions & 0 deletions website/docs/essentials/combining_requests/functional_ref/raw.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ignore_for_file: unused_local_variable

import 'package:riverpod_annotation/riverpod_annotation.dart';

final otherProvider = Provider<int>((ref) => 0);

/* SNIPPET START */
final provider = Provider<int>((ref) {
// "Ref" can be used here to read other providers
final otherValue = ref.watch(otherProvider);

return 0;
});
/* SNIPPET END */
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ignore_for_file: unused_local_variable, avoid_print

import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'codegen.g.dart';

final otherProvider = Provider<int>((ref) => 0);

/* SNIPPET START */
@riverpod
int example(ExampleRef ref) {
ref.listen(otherProvider, (previous, next) {
print('Changed from: $previous, next: $next');
});

return 0;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import raw from '!!raw-loader!./raw.dart';
import codegen from '!!raw-loader!./codegen.dart';

export default { raw, codegen };
13 changes: 13 additions & 0 deletions website/docs/essentials/combining_requests/listen_example/raw.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ignore_for_file: unused_local_variable, avoid_print
import 'package:riverpod_annotation/riverpod_annotation.dart';

final otherProvider = Provider<int>((ref) => 0);

/* SNIPPET START */
final provider = Provider<int>((ref) {
ref.listen(otherProvider, (previous, next) {
print('Changed from: $previous, next: $next');
});

return 0;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ignore_for_file: unused_local_variable

import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'codegen.g.dart';

@riverpod
int other(OtherRef ref) => 0;

/* SNIPPET START */
@riverpod
class Example extends _$Example {
@override
int build() {
// "Ref" can be used here to read other providers
final otherValue = ref.watch(otherProvider);

return 0;
}
}
/* SNIPPET END */

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import raw from '!!raw-loader!./raw.dart';
import codegen from '!!raw-loader!./codegen.dart';

export default { raw, codegen };
19 changes: 19 additions & 0 deletions website/docs/essentials/combining_requests/notifier_ref/raw.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// ignore_for_file: unused_local_variable

import 'package:riverpod_annotation/riverpod_annotation.dart';

final otherProvider = Provider<int>((ref) => 0);

/* SNIPPET START */
final provider = NotifierProvider<MyNotifier, int>(MyNotifier.new);

class MyNotifier extends Notifier<int> {
@override
int build() {
// "Ref" can be used here to read other providers
final otherValue = ref.watch(otherProvider);

return 0;
}
}
/* SNIPPET END */
Loading