I have two collections in firestore, 'users' and 'posts'. HomePage is where all the posts are displayed in a listview and every post has a 'like' button. I'm saving the liked posts in a set final _likedPosts = Set<Posts>(); on the page but it only temporarily saves the liked posts and it loses all that data once the app is closed. How can I save the user's _likedPosts permanently so that the data is retained. What query should I make for the users to retain the _likedPosts? or is there any other way for this?
This is how the Icon and onTap is currently,
final _likedPosts = _savedPosts.contains(post);
Icon(_likedPosts ? Icons.favorite : Icons.favorite_border,
color: _likedPosts ? Colors.red : null),
onTap: () {
setState(() {
if (_likedPosts) {
_savedPosts.remove(post);
} else {
_savedPosts.add(post);
}
});
}