I have data in a Map that needs to be displayed on the screen. How can I display data from a Map in a column?
class _HomePageState extends State<HomePage> {
final Map<String, String> profile = {
'name': 'Name',
'date of birth': 'Date',
'profile update date': 'Date',
};
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Column(
children: [
],
),
),
);
}
CodePudding user response:
final Map<String, String> profile = {
'name': 'Name',
'date of birth': 'Date',
'profile update date': 'Date',
};
ListView.builder(
itemCount: profile.length,
builder:(context,index){
return Column( children:[
Text(profile[index]['name']),
SizedBox(height: 10),
Text(profile[index]['date of birth']),
SizedBox(height: 10),
Text(profile[index]['profile update date'])
]
);
});
CodePudding user response:
Column(
children: [
Text(profile['name'])
]
)
CodePudding user response:
You can wrap the map into rows like this:
return Scaffold(
body: Container(
child: Column(
children: profile.keys.map((key) => Row(children: [Text(profile[key]!)],)).toList(),
),
),
);