Skip to content

Commit

Permalink
Fixed the usage of asyncValue.guard in the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
drown0315 committed Mar 20, 2024
1 parent 6557620 commit 0aea123
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/flutter_riverpod/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 2.5.2 - 2024-03-18

- Fixed various typos in the documentation (thanks to @kevalvavaliya)

- Fixed the usage of asyncValue.guard in the documentation (thanks to @drown0315)
## 2.5.1 - 2024-03-10

- Deprecate `ProviderScope.parent` due to fundamentally not working.
Expand Down
13 changes: 10 additions & 3 deletions packages/riverpod/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ abstract class AsyncValue<T> {
/// try {
/// final response = await dio.get('my_api/data');
/// final data = MyData.fromJson(response);
/// state = AsyncValue.data(data);
/// if(mounted){
/// state = AsyncValue.data(data);
/// }
/// } catch (err, stack) {
/// state = AsyncValue.error(err, stack);
/// if(mounted){
/// state = AsyncValue.error(err, stack);
/// }
/// }
/// }
/// }
Expand All @@ -151,10 +155,13 @@ abstract class AsyncValue<T> {
/// Future<void> sideEffect() async {
/// state = const AsyncValue.loading();
/// // does the try/catch for us like previously
/// state = await AsyncValue.guard(() async {
/// final newState = await AsyncValue.guard(() async {
/// final response = await dio.get('my_api/data');
/// return Data.fromJson(response);
/// });
/// if(mounted){
/// state = newState;
/// }
/// }
/// }
///
Expand Down

0 comments on commit 0aea123

Please sign in to comment.