Closed alfalcon90 closed 10 months ago
Hi again, finally got to my laptop.
Freezed plays wonderfully with ReArch, but definitely do not use notifiers in conjunction with ReArch. The equivalent is just a capsule with a different API exposed like:
(List<City>, {void Function(City) addCity,}) citiesManager(CapsuleHandle use) {
final (cities, setCities) = use.state(<City>[]);
return (
cities,
addCity: (city) => setCities([...cities, city]),
// any other functions you would normally put in your notifier...
);
}
You can add any other functions to the return value of the capsule as you see fit.
I also would suggest using fast_immutable_collections
in the case of immutable lists here. It is much faster and much more ergonomic when handling scenarios like this.
Let me know if you have any other questions!
For some of the more complex parts of my projects I often use
state_notifier
andfreezed
data classes for grouping methods and state under their own respective classes. For example:I tried looking through the documentation but couldn't find an example of using
rearch
for building something like this. The class below is my quick and dirty initial stab at accomplishing a similar thing but I could be way off. Either some official recommended way of doing this in the documentation or aRearchNotifier
class that implements it the right way would be great.