Its not easy for me to explain what I want and thats why I have created this demo to make my point clear…
I have a data mymap which key is based on random number and value is bool
in my list tile of listview builder, I want sometime value and sometime key in it’s
title,subtitle,trailing,leading
class HomeScreen extends StatelessWidget {
Map<String,dynamic> mymap={
'${Random().nextInt(255)}':false,
'${Random().nextInt(255)}':true,
'${Random().nextInt(255)}':true,
'${Random().nextInt(255)}':false,
};
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: 1,
itemBuilder: (context,index){
return ListTile(
title: Text(
//firstkey + value
),
subtitle: Text(
//secondkey +value
),
leading: Text(
//thirdkey only
),
trailing: Text(
//fourthkey's value
),
);
});
}
}
>Solution :
You can get keys like here:
List keys = myMap.keys.toList();
And get access to keys in list tile like here:
Text(keys[2].toString()), // get key from list index