CreamyMilk / zukees

💼Monitor moni
MIT License
2 stars 0 forks source link

🤦‍♂️Wired Cart 🛒 implemenation #2

Closed CreamyMilk closed 3 years ago

CreamyMilk commented 3 years ago

The Cart cannot dynamically change when an items are added 😿.

When an item is added it does not appear in the cart because the provider is limited to the home named Route but the cart is an entirely new screen

CreamyMilk commented 3 years ago

So first solution was to turn to our trusty Nosql DB Hive🐝 to store product info so that they can be retrieved from the cart .But the runtime type inference decided to just make it quite challenging as show below.

//The Products data is stored in
List<Map<String,dynamic>> productsData;

//But to hive the value is 🐝 At runtime it changes to
_InternalLinkedHashMap<dynamic, dynamic> myData;

I am aware that i found a solution in the Simpmigration📱 app but is was to messy to actually be feasible.

CreamyMilk commented 3 years ago

from NoSQL 🔄 to SQL

Now that Hive🐝 was starting to be quite unwieldy I decided to try out SQFLITE📦📦 which was essentially storing the data in an SQL Table. At first it seemed quite straight forward till i came to the realizations that SQFLITE uses raw SQL queries to execute CRUD operation .

Yes I know this could be helpful if I just create a wrapper class to do the magic in the background but the most annoying issues is that the product data is constantly refreshed and the mere act of dropping and creating tables on every refresh seemed rather unnecessary . And as an added bonus the runtime size of the APK🤖 will increase greatly. Which may lead to my loyal customer deciding to just uninstall the app due to the shear size

CreamyMilk commented 3 years ago

Back to basics Provider 🙌

After endless searching on the best way to solve my problems I came across the Flutter article of state management . Their approach was quite straight forward

{"PowerPhrase😁":"Just lift up the state"}

That was just half the show👒 now the challenge was to change our data shape at runtime without triggering

setState((){
 //update CartValues
}) 

//everywhere .
CreamyMilk commented 3 years ago

So 🐝 Flutter_hive has a valuelistenable builder that automatically rebuilds its children if a value inside the 📦box changes,Was quite helpful.