Search code examples
flutterdartsharedpreferences

how to add a list of an item to cart using shared preferences [flutter]


so currently i'm learning about flutter & dart.

so, i was trying to make a cart system using shared_preferences package, but i still don't know how.

i want to have a list of an item in cart, here's what pretty much i'm trying to achieve using shared_preferences

[{"id":109,"itemCount":"1","price":1269945,"image":"image.jpg"}, {"id":200,"itemCount":"1","price":2090424,"image":"image.jpg"}]

so if anyone know how to do it, or have a suggestion on how to do it without shared_preferences, please answer this questions.

Thanks in advance by the way.


Solution

  • Instead of using shared_preferences, I suggest you to use a State Manager like Provider/RiverPod, it is designed also for this kind of situations. Shared Preferences is designed to be used for storing small informations.

    RiverPod package: RiverPod

    Provider package: Provider

    Small guide for Provider