有人可以解释为什么我不能在下拉列表中选择另一个项目。当我点击时,下拉按钮重置。我没有收到任何错误,所以我不知道问题出在哪里。
我遵循了颤振文档,但总是出现相同的错误。
Widget dropdown(BuildContext context) {
CollectionReference sneakers =
FirebaseFirestore.instance.collection("sneakers");
final _raffle = TextEditingController();
String dropdownValue;
return Column(
children: [
TextFormField(
controller: _raffle,
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
decoration: InputDecoration(
labelText: "raffles",
),
),
StreamBuilder<QuerySnapshot>(
stream: sneakers.snapshots(),
builder:
(BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Text("Loading");
}
return new DropdownButton<String>(
value: dropdownValue,
icon: const Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
print(newValue);
});
},
items: snapshot.data.docs.map((DocumentSnapshot doc) {
return new DropdownMenuItem<String>(
value: doc.reference.id.toString(),
child: Text(
doc['name'],
));
}).toList(),
);
},
),