• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to get a subset of items from a list in an AsyncNotifierProvider in Riverpod 2.0?

Resolved: How to get a subset of items from a list in an AsyncNotifierProvider in Riverpod 2.0?

0
By Isaac Tonny on 16/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve How to get a subset of items from a list in an AsyncNotifierProvider in Riverpod 2.0?

Question:

I have recently started using Riverpod 2.0 but I’m constantly running into the following issue / limitation which I dont know how to solve neatly. I will illustrate this using the code from the docs as found on the Riverpod 2.0 Docs for the NotifierProvider.
The AsyncTodosNotifier contains a state with a list of Todo items, all of which have their fields. Now lets suppose I want to have a screen with just a list of all completed Todos. How can I accomplish this in a provider, rather than push this code to the build method of the widget. The latter not being reusable, not easily testable and not optimized in rendering.
Here the code that accomplishes the task. But the filtering happens within the .when() in the build method, which is not the place I would like this to happen
My goal is to have a second AsyncNotifierProvider or FutureProvider which re-uses the data fetched by the main AsyncNotifierProvider which will hold the state of all items.

Best Answer:

Got some help from the Riverpod Discord server.
The answer is to setup another provider that listens to the .future value of the original AsyncNotifierProvider.
So in this case:

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

flutter riverpod
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Vaadin 14.9 – Redirect on Session Destroy Event

26/03/2023

Resolved: How to separate multiple answers in one column, for multiple columns, by creating extra columns

26/03/2023

Resolved: How to set consistent decimal separators in R data frame?

26/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.