[英]pass dropdown selected value to firebase collection in Dart
Need to pass dropdown selected value from OrderListScreen to firebase collection order.需要将 OrderListScreen 中的下拉选择值传递给 firebase 集合订单。 Dont know the proper way of passing this field value to be reflect in firebase.不知道传递此字段值以反映在 firebase 中的正确方法。 Code for dropdown is ok need to get that selected value to be able to pass it to orderStatus field.下拉代码是好的,需要获取所选值才能将其传递给 orderStatus 字段。 Please help.请帮忙。
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/foundation/key.dart';
import 'package:flutter/src/widgets/framework.dart';
class OrderListScreen extends StatefulWidget {
const OrderListScreen({Key? key}) : super(key: key);
@override
State<OrderListScreen> createState() => _OrderListScreenState();
}
class _OrderListScreenState extends State<OrderListScreen> {
String? newvalue;
@override
Widget build(BuildContext context) {
String dropdownvalue = 'Pending';
return Material(
child: Container(
child: Column(
children: <Widget>[
Text(" Please select the order status from the dropdown Below:",
style: TextStyle(backgroundColor: Colors.orange)),
Container(
child: Material(
child: DropdownButton<String>(
value: newvalue,
items: <String>[
'Pending',
'Confirmed',
'Dispatched',
'Received'
].map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String? newvalue) {
setState(() {
this.newvalue = newvalue;
});
},
),
)),
],
),
),
);
}
}
This question has already been answered in this thread这个问题已经在这个帖子中回答了
on select something from dropdown the value will be stored in
dropdownValue
在 select 上,下拉列表中的某些内容将存储在dropdownValue
中then to store to firebase然后存储到 firebase
FirebaseFirestore.instance
.collection("collection")
.doc(result.user.uid)
.set({
'Name': _Name.text,
'myDropdownValue":dropdownValue
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.