Closed hamzamon closed 3 years ago
Hey!
Thanks for filing issue #1! As soon as I get some time I'll send over an example.
In the meantime, there's multiple ways to do it. What you're looking to iterate in for each You could:
a) Maybe the easiest, use if
s, so if i
is 1
then you'd render the date, likewise for the rest
b) Another option would be to have a map that links int i
to a certain piece of data in SalesHistory
, for example
Map<int, SalesHistory> _map = {
0: salesHistory[j].date,
1: salesHistory[j].orderId,
2: salesHistory[j].item,
3: salesHistory[j].price,
4: salesHistory[j].cost,
5: salesHistory[j].profit,
};
This might be placed inside the class, and may not use j
but grab the data directly from the JSON.
If you need any other help or further guidance please let me know! This should give you some ideas on how to tackle it.
In the meantime, there's multiple ways to do it. What you're looking to iterate in for each You could:
a) Maybe the easiest, use
if
s, so ifi
is1
then you'd render the date, likewise for the rest b) Another option would be to have a map that linksint i
to a certain piece of data inSalesHistory
, for exampleMap<int, SalesHistory> _map = { 0: salesHistory[j].date, 1: salesHistory[j].orderId, 2: salesHistory[j].item, 3: salesHistory[j].price, 4: salesHistory[j].cost, 5: salesHistory[j].profit, };
This might be placed inside the class, and may not use
j
but grab the data directly from the JSON.If you need any other help or further guidance please let me know! This should give you some ideas on how to tackle it.
Thank you for your prompt reply, I have tried with given hint as
dataCellBuilder: (i, j) => Text(_map[i][j]),
Map<int, SalesHistory> _map = { 0: salesHistory[j].date, 1: salesHistory[j].orderId, 2: salesHistory[j].item, 3: salesHistory[j].price, 4: salesHistory[j].cost, 5: salesHistory[j].profit, };
But actully The element type 'String' can't be assigned to the map value type 'SalesHistory'. Your help highly appreciated.
Yep, that was my bad, forgot to change it. Try putting dynamic or String instead of SalesHistory in the map type.
In the meantime, there's multiple ways to do it. What you're looking to iterate in for each You could: a) Maybe the easiest, use
if
s, so ifi
is1
then you'd render the date, likewise for the rest b) Another option would be to have a map that linksint i
to a certain piece of data inSalesHistory
, for exampleMap<int, SalesHistory> _map = { 0: salesHistory[j].date, 1: salesHistory[j].orderId, 2: salesHistory[j].item, 3: salesHistory[j].price, 4: salesHistory[j].cost, 5: salesHistory[j].profit, };
This might be placed inside the class, and may not use
j
but grab the data directly from the JSON. If you need any other help or further guidance please let me know! This should give you some ideas on how to tackle it.Thank you for your prompt reply, I have tried with given hint as
dataCellBuilder: (i, j) => Text(_map[i][j]),
Map<int, SalesHistory> _map = { 0: salesHistory[j].date, 1: salesHistory[j].orderId, 2: salesHistory[j].item, 3: salesHistory[j].price, 4: salesHistory[j].cost, 5: salesHistory[j].profit, };
But actully The element type 'String' can't be assigned to the map value type 'SalesHistory'. Your help highly appreciated.
Can you please give me an example to define 'j'
Maybe a function along these lines can do the job:
Text getDataCell(i, j, List<int> salesHistory){
Map<int, dynamic> _map = {
0: salesHistory[j].date,
1: salesHistory[j].orderId,
2: salesHistory[j].item,
3: salesHistory[j].price,
4: salesHistory[j].cost,
5: salesHistory[j].profit,
};
return Text(_map[i]);
}
Basically, getDataCell will accept i, j and the list. Then, as j is the column or the item number we pick that. Lastly, we return the piece of data needed.
Done, Thank you very much.
My pleasure!
// Example List
Thank you.
Update by aguilaair (Code formatting)