I'm trying to add a favorites feature with flutter. If you activate it by clicking the Favorites button inside the page, you need to implement it so that the Favorites page marked as Favorite appears in the page selection window. getx was too complex to implement, so I gave up on it. Are there any other attractions or advice pages?
I've seen shared_preferences: ^2.0.7, but it's my first time developing an app, so it's difficult to develop because there are no examples.
CodePudding user response:
You might want to have a look to this flutter cookbook. While this will not teach you about shared preferences, it will basically implement the other functionalities you want. It's actually a great way to start learning Flutter which new Flutter users.
Once you understand this cookbook and feel confident, you might want to have a look at this flutter tutorial on shared preferences which is beginner friendly as well.
If you would take an advice, I would urge you to start with as little dependencies as you can and use them only when you need them. If you are new to flutter, and for a simple app, GetX is not needed and will disturb you more than help you.
CodePudding user response:
You could have a statefull widget on Page selection where you read from preferences in init state and give that value to the favorite icon (e.g. true icon color is red, false -> white). And pass a function such as (setState(() {favorite = !favorite});) to the second page. Then if user click on the favorite button on page 2 and navigates back, the color will change. Also don't forget to save it on prefs when you click the iconButton.