So as we know rawQuery from Sqlite returning <List<Map<String, Object?>>>.
I need data in this form :
//example
Map<String, List> _dataItems = {
'1st ': ['Name01', 'SubData01'],
'2th': ['Name02', 'SubData02'],
'3th': ['Name03', 'SubData03'],
};
IM trying something like this:
List<Map<String, dynamic>> result = await dbService.getData();
var map = Map<String, dynamic>();
for (int i = 0; i < result.length; i++) {
map['placeCol'] = result[i]['Name01']
...
}
So basically return data from db placeCol to be key and few other String in the List, like in example data.
With this approach:
Map<String, List> _map = {};
for (int i = 0; i < result.length; i++) {
_map[result[i]['placeCol']] = [result[i]['NameCol']];
}
I get this:
{1st : [Name 01]}
{1st : [Name 02]}
{1st : [Name 03]}
{1st : [Name 04]}
{1st : [Name 05]}
{2st : [Name 01]}
{2st : [Name 02]}
{2st : [Name 03]}
Instad of this:
{1st : [Name 01, Name02,Name03,Name04,Name05],
2st : [Name 01, Name02,Name03]
}
Try Creating a map Directly from result map So Something like this inside for loop
var map = result.elementAt(i)
And then you can use map to get data you want print it see how it looks to get a better idea of it's structure and use that to place it wherever you want
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.