I need use a string as a value in the flutter dropdown. But returns
Another exception was thrown: 'package:flutter/src/material/dropdown.dart': Failed assertion: line 609 pos 15: 'items == null || items.isEmpty || value == null || items.where((DropdownMenuItem item) => item.value == value).length == 1': is not true.
Full log here.
The code is
items: dataMaker.map((item) {
return new DropdownMenuItem<String>(
child: new Text(item['fabricante'],
textAlign: TextAlign.center),
value: item['fabricante'], //FAIL
);
}).toList(),
So my question in: How can i use a string as item value? Another solution is get the text of dropdown but i don′t know how.
--SOLUTION--
With this code I can find all the elements in the dataMaker list that have the same text as the drop-down menu.
var test =dataMaker.firstWhere((fabricante) => fabricante["id"].toString() == dropdownSelectionMaker);
dataModelo = dataMaker.where((modelo) => modelo["fabricante"] == test["fabricante"]).toList();
See Question&Answers more detail:os