Last active
December 21, 2021 19:30
-
-
Save kevindmoore/e066e501367d0c480a2d92abcdb8957e to your computer and use it in GitHub Desktop.
Riverpod Example
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
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