In this example, I'm going to create a basic data model that will be a blueprint for my data. The data I'm working on is the transaction data for weekly shopping and it will have id, title, amount, and date.
Think of your data model as a blueprint for each row, not a table!
Note that I could use a map for this, but the class blueprint is a preferred method, especially when you are working with your own API and rest API.
first I create a new file and name it appropriately to my data, I will name it transaction.dart , and the blueprint looks like this:
now to use this class in my widget, I first import it:
and inside my widget where I need the data, I define a list of data:
And I can now use transactions.map to loop through my transactions and do something with the data available in my transaction blueprint, as shown below:
note : map returns an iterable so you need to convert it to a list and Column expects a list of widgets so in your map you must return a widget.
map((tx){}) where tx is Transaction blueprint and transactions is a list of Transaction.