rrousselGit / riverpod

A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
https://riverpod.dev
MIT License
5.82k stars 888 forks source link

update the TODO example. #3475

Closed dogomayana closed 1 month ago

dogomayana commented 1 month ago

class TodoList extends Notifier<List> { @override List build() => [ const Todo(id: 'todo-0', description: 'Buy cookies'), const Todo(id: 'todo-1', description: 'Star Riverpod'), const Todo(id: 'todo-2', description: 'Have a walk'), ];

void add(String description) { state = [ ...state, Todo( id: _uuid.v4(), description: description, ), ]; } ... The "extend Notifier" throws a subclass error when build-runner run, this means, the "Notifier" is not the right notifier for that instance.

This worked for me.

riverpod riverpod1

In summary, substitute "Notifier" with "AutoDisposeNotifier".

rrousselGit commented 1 month ago

The todo example is correct. You used autoDispose, when the example does not.

dogomayana commented 1 month ago

I didn't explicitly use the autoDispose. I copied the exact code from the TODO example and ran the build-runner which generated the autoDispose.

rrousselGit commented 1 month ago

You used AutoDisposeNotifierProvider in your code snippet, which isn't used anywhere in the documentation