I am using riverpod package for state management in a Flutter app and I have a search sort provider as follows:
final searchSortStateProvider = StateProvider<SearchSort?>((ref) { return SearchSort.relevance; });
But when the user searches again I want to reset the state of the search sort provider using the following code:
ref.read(searchSortStateProvider.notifier).state = SearchSort.relevance;
It throws:
"setState() or markNeedsBuild called during build"
Exception because I call it inside the init() method of the parent widget.
My question is how can I change the state of the provider without needing to rebuild the sort widget?