Home > Software design >  how to store likes data in flutter
how to store likes data in flutter

Time:12-19

I'm developing an app in which I need to show come "coupons" I get from the API. I also have a "liked coupons" page where I need to show the ones the user has liked. I'm facing 2 problems here: 1- I don't know how to store likes, should I implement a local database for everything or should I ask our back-end team to save the liked/not liked state on the server? 2- I have a model class for coupons, and I have a coupon_list widget which is a horizontal listview.builder(). the problem is that some coupons are being showed in 2 or 3 different lists and I need them to all turn to liked when user likes an instance from a single list. how can I do that? (I want to do something like working with pointers in c , passing the ACTUAL variable instead of it's value so it changes globally)

CodePudding user response:

I would like to suggest you to store it in server as well. (Ask to your back-end team to add parameter) So that if user logout or sign in from different device "liked coupons" data will be available in all cases.

And for 2) multiple coupon entry you have to manage it via unique id. Like every coupon has its unique series no / pattern num. So you can put condition on that. i.e. Add "unique_no" to liked_list from all available list of coupon

CodePudding user response:

Solution

Use Shared Preferences! This is something like a database on the device you are currently running. So if the user makes a like you can save that on their device!

To add Shared Preferences to your app look this video


Hope it helps!

  • Related