-
-
Notifications
You must be signed in to change notification settings - Fork 956
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a migration example for
ChangeNotifier
- Loading branch information
Showing
5 changed files
with
178 additions
and
4 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
website/docs/migration/from_change_notifier/from_change_notifier.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// ignore_for_file: avoid_print | ||
|
||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'from_change_notifier.g.dart'; | ||
|
||
class Todo { | ||
const Todo(this.id); | ||
final int id; | ||
} | ||
|
||
/* SNIPPET START */ | ||
@riverpod | ||
class MyNotifier extends _$MyNotifier { | ||
@override | ||
FutureOr<List<Todo>> build() { | ||
// request mock | ||
return Future.delayed(const Duration(seconds: 1), () => <Todo>[]); | ||
} | ||
|
||
Future<void> addTodo(int id) async { | ||
state = const AsyncLoading(); | ||
state = await AsyncValue.guard(() { | ||
// request mock | ||
return Future.delayed(const Duration(seconds: 1), () => [Todo(id)]); | ||
}); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
website/docs/migration/from_change_notifier/from_change_notifier.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import raw from "!!raw-loader!./raw.dart"; | ||
import codegen from "!!raw-loader!./from_change_notifier.dart"; | ||
|
||
export default { | ||
raw, | ||
hooks: raw, | ||
codegen, | ||
hooksCodegen: codegen, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// ignore_for_file: avoid_print | ||
|
||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
class Todo { | ||
const Todo(this.id); | ||
final int id; | ||
} | ||
|
||
/* SNIPPET START */ | ||
@riverpod | ||
class MyNotifier extends AutoDisposeAsyncNotifier<List<Todo>> { | ||
@override | ||
FutureOr<List<Todo>> build() { | ||
// request mock | ||
return Future.delayed(const Duration(seconds: 1), () => <Todo>[]); | ||
} | ||
|
||
Future<void> addTodo(int id) async { | ||
state = const AsyncLoading(); | ||
state = await AsyncValue.guard(() { | ||
// request mock | ||
return Future.delayed(const Duration(seconds: 1), () => [Todo(id)]); | ||
}); | ||
} | ||
} | ||
|
||
final myNotifierProvider = AsyncNotifierProvider.autoDispose<MyNotifier, int>(MyNotifier.new); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters