2
I have a field DropDownMenu
and would like to fill in the Items
of it with the values of my Json. I have this code:
String _mySelection;
List<Map> _myJson = [{"id":0,"name":"<New>"},{"id":1,"name":"Test Practice"}];`
That works in the DropDownMenu
:
items: _myJson.map((Map map) {
return new DropdownMenuItem<String>(
value: map["id"].toString(),
child: new Text(
map["name"],
),
);
}).toList(),`
But what I wanted was instead of passing the Json mounted on _mySelection
would pass the value returned from my class ResultLogin
static ResultLogin fromJson(Map<String, dynamic> json) {
List<ZLoginResultSchema> schemasList = [];
for (var s in json['schemas']) {
schemasList.add(ZLoginResultSchema.fromJson(s));
}
}
My class ZLoginResultSchema
where I assemble the list of schemas
:
class ZLoginResultSchema {
final String name;
final String fullname;
ZLoginResultSchema({this.name, this.fullname});
ZLoginResultSchema.fromJson(Map<String, dynamic> json):
name = json['name'],
fullname = json['fullname'];
Map<String, dynamic> toJson() =>
{
'name': name,
'fullname': fullname,
};
}
How can I take the value of schemaList
class ResultLogin
, and pass the Function _myJson
of my Page?
_Myselection is only the variable that I will store the selected value, I was able to get the list values by directly passing the list class in the map.
items: schemas.map((ZLoginResultSchema map) {
 return new DropdownMenuItem<String>(
 value: map.name,
 child: new Text(map.fullname),
 );
 }).toList()
– Luan Martins Gepfrie