Skip to content

Instantly share code, notes, and snippets.

@kevindmoore
Last active December 21, 2021 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevindmoore/e066e501367d0c480a2d92abcdb8957e to your computer and use it in GitHub Desktop.
Save kevindmoore/e066e501367d0c480a2d92abcdb8957e to your computer and use it in GitHub Desktop.
Riverpod Example
final todoManagerProvider = StateNotifier<TodoManager>((ref) {
return TodoManager();
});
class TodoManager extends StateNotifier<TodoFiles> {
TodoManager() : super(TodoFiles(<TodoFile>[]));
void addTodoFile(TodoFile todoFile) {
state = TodoFiles([...state.files, todoFile]);
print('addTodoFile: Now has ${state.files.length} files');
}
void clear() {
state = TodoFiles(<TodoFile>[]);
}
void removeTodoFile(TodoFile todoFile) {
state.files.remove(todoFile);
state = TodoFiles([...state.files]);
}
void addTodoFiles(List<TodoFile> todoFiles) {
state.files.addAll(todoFiles);
state = TodoFiles([...state.files]);
}
}
class TodoFile {
String name,
List<Category> categories,
}
final todoFile = TodoFile(name: platformFile.name, categories: categories);
ref.read(todoManagerProvider).addTodoFile(todoFile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment