riverpod
riverpod copied to clipboard
Fixed `AsyncValue.guard` documentation
Fixed the usage of asyncValue.guard in the documentation
Before:
/// Future<void> sideEffect() async {
/// state = const AsyncValue.loading();
/// try {
/// final response = await dio.get('my_api/data');
/// final data = MyData.fromJson(response);
/// state = AsyncValue.data(data);
/// } catch (err, stack) {
/// state = AsyncValue.error(err, stack);
/// }
/// }
/// }
After:
/// Future<void> sideEffect() async {
/// state = const AsyncValue.loading();
/// try {
/// final response = await dio.get('my_api/data');
/// final data = MyData.fromJson(response);
/// if(mounted){
/// state = AsyncValue.data(data);
/// }
/// } catch (err, stack) {
/// if(mounted){
/// state = AsyncValue.error(err, stack);
/// }
/// }
/// }
/// }
Because provider
may be disposed
after await
, add code to check if mounted.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]
).
-
[x] I have updated the
CHANGELOG.md
of the relevant packages. Changelog files must be edited under the form:## Unreleased fix/major/minor - Description of your change. (thanks to @yourGithubId)
-
[x] If this contains new features or behavior changes, I have updated the documentation to match those changes.
⚠️ No Changeset found
Latest commit: 2774a9bc91339d8b60ff2cd1d15bebedeeb14fa8
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR