Skip to content

Commit

Permalink
Fix ChangeNotifierProvider dartdoc
Browse files Browse the repository at this point in the history
fixes #2453
  • Loading branch information
rrousselGit committed Apr 13, 2023
1 parent 204bd4c commit 29b89c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
4 changes: 4 additions & 0 deletions packages/flutter_riverpod/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased fix

- Fix `ChangeNotifierProvider` docs

## 2.3.4 - 2023-04-07

- Fixes an issue with nested ProviderScope (thanks to @jeiea)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,23 @@ abstract class ChangeNotifierProviderRef<NotifierT extends ChangeNotifier?>
/// Using [ChangeNotifier], you could represent such state as:
///
/// ```dart
/// class TodosNotifier extends ChangeNotifier<List<Todo>> {
/// TodosNotifier(): super([]);
/// class TodosNotifier extends ChangeNotifier {
/// List<Todo> todos = [];
///
/// void add(Todo todo) {
/// state = [...state, todo];
/// todos.add(todo);
/// notifyListeners();
/// }
///
/// void remove(String todoId) {
/// state = [
/// for (final todo in state)
/// if (todo.id != todoId) todo,
/// ];
/// todos.removeWhere((todo) => todo.id == todoId);
/// notifyListeners();
/// }
///
/// void toggle(String todoId) {
/// state = [
/// for (final todo in state)
/// if (todo.id == todoId) todo.copyWith(completed: !todo.completed),
/// ];
/// final todo = todos.firstWhere((todo) => todo.id == todoId);
/// todo.completed = !todo.completed;
/// notifyListeners();
/// }
/// }
/// ```
Expand All @@ -60,7 +58,7 @@ abstract class ChangeNotifierProviderRef<NotifierT extends ChangeNotifier?>
/// ```dart
/// Widget build(BuildContext context, WidgetRef ref) {
/// // rebuild the widget when the todo list changes
/// List<Todo> todos = ref.watch(todosProvider);
/// List<Todo> todos = ref.watch(todosProvider).todos;
///
/// return ListView(
/// children: [
Expand Down
9 changes: 3 additions & 6 deletions website/docs/providers/change_notifier_provider/todos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ class TodosNotifier extends ChangeNotifier {

// Let's mark a todo as completed
void toggle(String todoId) {
for (final todo in todos) {
if (todo.id == todoId) {
todo.completed = !todo.completed;
notifyListeners();
}
}
final todo = todos.firstWhere((todo) => todo.id == todoId);
todo.completed = !todo.completed;
notifyListeners();
}
}

Expand Down

0 comments on commit 29b89c0

Please sign in to comment.