微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将 TypeAheadFormField 的属性传递给 Form Builder

如何解决将 TypeAheadFormField 的属性传递给 Form Builder

我花了两天时间寻找解决方案 - 现在快要疯了。

我使用 Form Builder 创建了一个工作表单,它可以正确地发布到 Firebase。当用户开始输入=(就像自动建议)时,我想让表单中的一个字段的值可以从列表中选择。

我沿着 TypeAheadFormField 的路线走下去,虽然它确实显示一个自动建议列表,并且按照我想要的方式工作,但我面临的挑战是我似乎无法将选定的选项传递给 Form Builder以及其他字段的结果作为表单的一部分。

TypeAheadFormField 没有属性选项,Form Builder 将其用作“_fbKey.currentstate.value”的一部分

我的代码如下 - 我可以将 TypeAheadFormField 的值传递给 Form Builder 发布到 Firebase 集合吗?

用户可以输入所有字段,结果被发布到 Firestore 集合中,没有任何错误(虽然练习是空的,因为我找不到正确的属性来拉入 fb_key)

我确实尝试过查看 Chip Input,它是 Form Builder 的一部分,但尽管不断搜索,我还是找不到一个足够接近我想要实现的示例以使其工作。

ListView(
                children: <Widget>[
                  FormBuilder(
                    // context,key: _fbKey,initialValue: {
                      'option 1': 3,'option 2': ['Test','Test 1'],'date': DateTime.Now(),},readOnly: false,child: Column(
                      children: <Widget>[
                        SizedBox(height: 15),SizedBox(height: 15),Container(
                          height: 60.0,child: TypeAheadFormField(
                              hideOnLoading: true,hideOnEmpty: true,getImmediateSuggestions: false,// initialValue: 'Name of Practise...',textFieldConfiguration: TextFieldConfiguration(
                                  // controller: controller,autofocus: true,style: TextStyle(
                                      color: Colors.black,fontSize: 17.0),decoration: Inputdecoration(
                                      labelText: 'Practise',labelStyle:
                                          TextStyle(color: Colors.black54),hintStyle: TextStyle(color: Colors.black),contentPadding:
                                          EdgeInsets.only(bottom: 15.0),// EdgeInsets.all(10.0),border: UnderlineInputBorder(
                                          borderSide: BorderSide(
                                              color: Colors.black54)),focusedBorder: UnderlineInputBorder(
                                        borderSide:
                                            BorderSide(color: Colors.black26),),// border: OutlineInputBorder(
                                      //     borderSide: BorderSide.none),hintText:
                                          'Start typing the name of your practise...'),controller: this._typeAheadController),suggestionsCallback: (pattern) {
                                if (pattern.length > 1) {
                                  return Providers.getSuggestions(pattern);
                                }
                                // return ProvidersDelay;
                              },itemBuilder: (context,suggestion) {
                                return ListTile(
                                    title: Text(
                                  suggestion,style: TextStyle(color: Colors.black),));
                              },onSuggestionSelected: (suggestion) {
                                this._typeAheadController.text = suggestion;
                              }),FormBuilderDateTimePicker(
                          attribute: 'dateStart',onChanged: _onChanged,inputType: InputType.date,format: DateFormat("dd-MM-yyyy"),decoration: const Inputdecoration(
                            labelText: 'Date of Practise',validator: (val) => null,// locale: Locale('ru'),// initialTime: TimeOfDay(hour: 8,minute: 0),initialValue: DateTime.Now(),// readonly: true,FormBuilderDateTimePicker(
                          attribute: 'dateEnd',decoration: const Inputdecoration(
                            labelText: 'Ending date of practise',FormBuilderCheckBoxGroup(
                          decoration: Inputdecoration(
                              labelText:
                                  'Choose some options'),attribute: 'extras',options: [
                            FormBuilderFieldOption(value: 'Option 1'),FormBuilderFieldOption(value: 'Option 2'),FormBuilderFieldOption(value: 'Option 3'),],Row(
                    children: <Widget>[
                      Expanded(
                        child: MaterialButton(
                          color: Colors.teal.shade400,child: Text('Reset',style: TextStyle(color: Colors.white)),onpressed: () {
                            _fbKey.currentState.reset();
                          },SizedBox(width: 20),Expanded(
                        child: MaterialButton(
                          color: Colors.teal.shade600,child: Text('Submit',onpressed: () {
                            if (_fbKey.currentState.saveAndValidate()) {
                              _firestore.collection('practise').add({
                                'practise':
                                    _fbKey.currentState.value['practise'],'startDate':
                                    _fbKey.currentState.value['dateStart'],'endDate': _fbKey.currentState.value['dateEnd'],'extras': _fbKey.currentState.value['extras'],'uid': getCurrentUID(),'status': '1'
                              });
                              print(_fbKey.currentState.value);
                              navigatetoSubPageCarCovered(context);
                            } else {
                              print(_fbKey.currentState.value);
                              print('validation Failed');
                            }
                          },

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。