我正在使用 Flutter_form_builder 和单选按钮。
我目前的文本字段使用他们的控制器正常工作,然后写入 firebase firestore。当我尝试将 Radio Button 变量分配为写入 firebase 时,它会同时写入 yes 和 no,即使它正在打印模拟器中选择的答案或控制台中的电话
您如何将其转换为上传正确答案的变量?
文件顶部
class _FFPServicesApplicationWidgetState extends State<FFPServicesApplicationWidget> {
var data;
bool autoValidate = true;
bool readOnly = false;
bool showSegmentedControl = true;
final GlobalKey<FormBuilderState> _fbKey = GlobalKey<FormBuilderState>();
ValueChanged _onReferral =(val) => print(val);
var referralOptions = ['Yes', 'No',];
get _fbUserKey => null;
void onItemTwoPressed(BuildContext context) => Navigator.push(context,
MaterialPageRoute(builder: (context) => HelpWidget()));
TextEditingController taskNameInputController;
TextEditingController taskEmailInputController;
TextEditingController taskPhoneInputController;
TextEditingController taskDescriptionInputController;
TextEditingController taskAgencyInputController;
@override
initState() {
taskNameInputController = new TextEditingController();
taskEmailInputController = new TextEditingController();
taskPhoneInputController = new TextEditingController();
taskDescriptionInputController = new TextEditingController();
taskAgencyInputController = new TextEditingController();
super.initState();
}
实际的小部件
FormBuilderRadio(
decoration: InputDecoration(labelText: 'Were you referred to us?'),
attribute: "Were you referred to us?",
onChanged: _onReferral,
validators: [FormBuilderValidators.required()],
options: [
FormBuilderFieldOption(
value: "Yes",
child: Text('Yes'),
),
FormBuilderFieldOption(
value: "No",
child: Text('No'),
),
],
),
提交按钮
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
MaterialButton(
child: Text("Submit"),
onPressed: () {
if (_fbKey.currentState.saveAndValidate()) {
print(_fbKey.currentState.value);
Firestore.instance
.collection('email')
.add({
"1. Name": taskNameInputController.text,
"2. Email": taskEmailInputController.text,
"3. Phone Number": taskPhoneInputController.text,
"4. Description": taskDescriptionInputController.text,
"5. Were you Referred": referralOptions,
"6. Agency Referring?": taskAgencyInputController.text,
"7. Children under 18": childrenOptions,
"8. Lincoln County?": countyOptions,
"9. Received Support in the past?": supportOptions,
});
}
},
),
MaterialButton(
child: Text("Reset"),
onPressed: () {
_fbKey.currentState.reset();
},
),
],
),