Widget locationList(String airportId) {
return Container(
child: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection("Airports").doc(widget.airportId).collection("Locations").snapshots(),
builder: (context, snapshot) {
if(snapshot.data == null){
return Container();
} else {
List<DropdownMenuItem<String>> locationItem = [];
for(int i=0;i<snapshot.data!.docs.length;i ){
DocumentSnapshot data = snapshot.data!.docs[i];
locationItem.add(
DropdownMenuItem<String>(
child: Text(
data["Location Name"],
),
value: "${data["Location Name"]}",
)
);
}
return Form(
key: _formKey,
child: Container(
alignment: Alignment.center,
height: 55,
width: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.black,width: 2)
),
child: DropdownButtonHideUnderline(
child: DropDownField(
value: value,
required: true,
items: locationItem,
enabled: true,
strict: false,
itemsVisibleInDropdown: 5,
onValueChanged: (value) {
setState(() {
this.value = value!;
locationId = value;
print(value);
print(locationId);
});
},
),
),
),
);
}
},
),
);
}
uj5u.com熱心網友回復:
在DropDownField你必須提供一個List<String>論點items:。
所以首先將您的locatioItem型別更改為List<String>
List<String> locationItem = [];
然后更改您的 for 回圈:
for (int i = 0; i < snapshot.data!.docs.length; i ) {
DocumentSnapshot data = snapshot.data!.docs[i];
locationItem.add(data["Location Name"]);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/426615.html
上一篇:如何為顫動中的每個步進器創建不同的BottomNavigationBar?
下一篇:為什么flutterscrollController.position.activity不能在普通小部件內部使用?
