I’m a little new to flutter. I have two DropdownButtons. The second depends on the selection of the first.
The data of the first I retrieve from the database. It poses no problem. Mais le second n’affiche aucune donnée bien que la liste de ses données ne soit pas vide.
First DropdownButton
Province? maProvince;
Ville? ville;
List<Ville> villes = [];
FutureBuilder<List<Province>>(
future: dbHelper.allProvinces(),
builder: (context,snapshot){
if(snapshot.connectionState == ConnectionState.waiting){
return CircularProgressIndicator();
}else if(snapshot.hasError){
return Text("Erreur du chargement des provinces.");
}else if (!snapshot.hasData || snapshot.data!.isEmpty){
return Text("Aucune province trouvée.");
}else{
List<Province> provinces = snapshot.data!;
return DropdownButtonFormField<Province>(
value: maProvince,
decoration: InputDecoration(
labelText: "Choisir une province",
border: OutlineInputBorder(),
),
items: provinces.map((province){
return DropdownMenuItem<Province>(
value: province,
child: Text((province.nomProvince))
);
}).toList(),
onChanged: (province) async{
final choises = await dbHelper.citiesOfAProvince(province!.id);
setState(() {
maProvince = province!;
villes = choises;
ville = choises[0];
});
},
);
}
}
)
The variable villes
,I use to load data of my second dropdownButton contains the data when I select an element from the first, but But no items are displayed.
Second DropdownButton
DropdownButtonHideUnderline(
child: ButtonTheme(
child: DropdownButtonFormField<Ville>(
value: ville,
onChanged: (Ville? newValue) async{
setState((){
ville = newValue!;});
},
items: villes.map((ville){
return DropdownMenuItem<Ville>(
child: Text(ville.nom_ville),
value: ville
);
}).toList(),
)
)
)
What am I not doing well?
Help please !