英文:
how to get list<map<string, dynamic> data each map key and value without identifying key
问题
var result = [
{
"SN": 1,
"HH_NAME": "MARYAN_MAXAMED_CIISE_XUSEEN",
"HH_NO": "BOSBAR0222598",
"TELEPHONE": 906689662
},
{
"SN": 3,
"HH_NAME": "HANI_AADAN_CABDI",
"HH_NO": "BOSBAR0167538",
"TELEPHONE": 905398109
},
{
"SN": 4,
"HH_NAME": "MAXAMED_AXMED_CABDILAAHI",
"HH_NO": "BOSBAR0192870",
"TELEPHONE": 907923390
},
{
"SN": 2,
"HH_NAME": "HIBAAQ_AADAN_CABDI",
"HH_NO": "BOSBAR0167539",
"TELEPHONE": 907545689
},
{
"SN": 5,
"HH_NAME": "MAXAMED_AXMED_KILWE",
"HH_NO": "BOSBAR0168767",
"TELEPHONE": 907329789
}
];
Expanded(
child: ListView.builder(
itemCount: result.length,
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (_, index) {
Map map = result[index];
return Card(
elevation: 12,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
for (var value in map.values)
for (var key in map.keys)
Align(
alignment: Alignment.centerLeft,
child: Text(
key.toString() +
' : ' +
value.toString(),
),
),
],
),
),
);
},
),
),
英文:
var result = [
{
"SN": 1,
"HH_NAME": "MARYAN_MAXAMED_CIISE_XUSEEN",
"HH_NO": "BOSBAR0222598",
"TELEPHONE": 906689662
},
{
"SN": 3,
"HH_NAME": "HANI_AADAN_CABDI",
"HH_NO": "BOSBAR0167538",
"TELEPHONE": 905398109
},
{
"SN": 4,
"HH_NAME": "MAXAMED_AXMED_CABDILAAHI",
"HH_NO": "BOSBAR0192870",
"TELEPHONE": 907923390
},
{
"SN": 2,
"HH_NAME": "HIBAAQ_AADAN_CABDI",
"HH_NO": "BOSBAR0167539",
"TELEPHONE": 907545689
},
{
"SN": 5,
"HH_NAME": "MAXAMED_AXMED_KILWE",
"HH_NO": "BOSBAR0168767",
"TELEPHONE": 907329789
}
];
Expanded(
child: ListView.builder(
itemCount: results.length,
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (_, index) {
Map map = results[index];
return Card(
elevation: 12,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
for (var value in map.values)
for (var key in map.keys)
Align(
alignment: Alignment.centerLeft,
child: Text(
key.toString() +
' : ' +
value.toString(),
),
),
],
),
),
);
},
),
),
I am doing here student results app, I converted csv to json data then I sent it to database. now I want to to get back and get all map data without identifying subjects or any other key.
if any one has more educated then me about this topic help me to do it.
many thanks.
答案1
得分: 2
不使用for循环
,你可以在results[index]
的条目上使用map
方法,它将返回results[index]
中项目的MapEntry,然后你可以使用它的key
和value
来生成你的ListView的项目。尝试这样做:
Column(
children: map.entries.map((e) => Align(
alignment: Alignment.centerLeft,
child: Text(
e.key.toString() + ' : ' + e.value.toString(),
),
),).toList()
),
英文:
Instead of for loop
, you can use map
method on your results[index]
's entries, it will return you MapEntry of your items inside results[index]
, then you can use its key
and value
to generate your listview's items. Try this:
Column(
children: map.entries.map((e) => Align(
alignment: Alignment.centerLeft,
child: Text(
e.key.toString() + ' : ' + e.value.toString(),
),
),).toList()
),
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论