-2
Exception that appears:
Exception Caught by widgets library
The following was thrown building Futurebuilder(Dirty, state: _Futurebuilderstate#74679): type '(City) => Dropdownmenuitem' is not a subtype of type '(Map) => Dropdownmenuitem' of 'f'
I use the Stateful Class:
class Sincronismo extends StatefulWidget {
@override
_SincronismoState createState() => _SincronismoState();
}
class _SincronismoState extends State<Sincronismo> {
// return Users.fromJson(jsonresponse[0]);
**Aqui pego os dados da Classe DB:**
getCidade( ) async {
DBAvaliacoes db = new DBAvaliacoes();
List city = await db.getCitys();
return city;
}
Cidade selectedCountry;
Future _future;
@override
void initState() {
_future = getCidade();
super.initState();
}
@override
Widget build(BuildContext context) {
return FutureBuilder (
future: _future ,
builder: (context, snapshot){
if(snapshot.hasError)
return Text(snapshot.error);
if (snapshot.hasData) {
return DropdownButtonFormField(
decoration: new InputDecoration(icon: Icon(Icons.language)), //, color: Colors.white10
value: selectedCountry,
The exception is when you get here:
items: snapshot.data.map<DropdownMenuItem<Cidade>>((Cidade city) {
return DropdownMenuItem<Cidade>(
value: city,
child: Text(city.descricao_cidade, style: TextStyle(color: Color.fromRGBO(58, 66, 46, .9))),
);
})
.toList(),
onChanged: (Cidade newValue) {
setState(() => selectedCountry = newValue);
// selectedCountry = newValue;
print(newValue.id);
print(newValue.descricao_cidade);
},
);
}
else{
return CircularProgressIndicator();
}
}
/**********************/
);
}}
Within the
db. getCitys()
Do you do some treatment to bring the City Object? If you do not do this treatment, it is returning a Map and not the model– mrocigno