【问题标题】:How to add autofill dropdown in flutter?如何在颤振中添加自动填充下拉菜单?
【发布时间】:2020-12-31 07:40:35
【问题描述】:

我已经做了一个城市的下拉列表,城市列表来自 API。当用户点击 GPS 按钮时,它会自动填充下拉字段。我应该如何在下拉列表中自动填写城市名称?我尝试在文本字段中使用下拉菜单

TextFormField(
                          controller: city,
                      decoration:InputDecoration(
                         border:InputBorder.none,
                          prefix: DropdownButtonFormField<String>(
                         
                              decoration: InputDecoration.collapsed(
                                  hintText: 'select',
                                  hintStyle: TextStyle(fontSize: 12,color: Colors.grey.shade600),
                                ),
                                value:type,
                                validator: (value) => value == null? 'please select': null,
                                onChanged: (String newValue) {
                                  setState(() {
                                    type = newValue;
                         
                                  });
                                },
                                items: List?.map((item){
                                  return DropdownMenuItem(
                                    onTap: (){
                                      selectedCity=item['city'];
                                      // print(selectedCity);
                                    },
                                    value: item['id'].toString(),
                                    child: Padding(
                                      padding: const EdgeInsets.only(left:15.0,top: 13.0),
                                      child: Text(item['city'],style: TextStyle(fontSize: 12,color: Colors.grey.shade600),),
                                    ),
                                  );
                                })?.toList()??[]
                            ),
                      ),
                      ),

【问题讨论】:

    标签: flutter dropdown textfield autofill


    【解决方案1】:

    您可以使用现成的自动完成包。

    一些例子:

    https://pub.dev/packages/autocomplete_textfield

    https://pub.dev/packages/dropdownfield

    【讨论】:

    • 它会从列表中自动完成,但我不想要这个。我在问题中提到,当用户单击 GPS 按钮时,此下拉字段会显示通过 GPS 跟踪获得的城市名称。
    • 是的,当然,您可以将城市列表注入此下拉列表。
    • 任何其他快速修复,因为 dropdownfield 正在创建问题并且 nit 显示下拉列表。
    猜你喜欢
    • 2021-06-08
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多