Replies: 3 comments
-
By using When using |
Beta Was this translation helpful? Give feedback.
-
If using keepAlive: false, then the result would not keep when moving to another page |
Beta Was this translation helpful? Give feedback.
-
If you want only last result of your filter, then I would remove the parameter in @Riverpod(keepAlive: true)
class TodoList extends _$TodoList {
String _filter = '';
@override
List<String> build() {
final allTodos = ref.watch(todosProvider);
return _filterList(allTodos);
}
List<String> _filterList(List<Todo> todos) {
// filter todos using _filter
}
void applyFilter(String filter) {
_filter = filter;
final todos = ref.read(todosProvider);
state = _filterList(todos);
// or you can just store _filter and ref.invalidateSelf()
} Your pages would watch the last filtered list. |
Beta Was this translation helpful? Give feedback.
-
From the document, one state per parameter combination will be created, which can lead to memory leaks.
How to ensure that when creating a new provider, the previous provider is automatically cleared
Beta Was this translation helpful? Give feedback.
All reactions