选择列表视图项,在表单字段中放置值,然后关闭列表视图 - Flutter

问题描述

我有一个连接到谷歌地点 api 的列表视图,它会随着用户输入地址而更新。当用户单击地址时,我希望将地址放置在文本字段中并关闭列表视图。

下面代码中的selectedItem是用户选择的项目。我正在尝试使用 selectedItem 更新 textformfield。有什么想法吗?

TextFormFiled 和 ListView.builder:

    TextFormField(
      controller: _controller,decoration: textInputdecoration.copyWith(
          labelText: 'Address or Perferred City'),),ListView.builder(
        physics: NeverScrollableScrollPhysics(),shrinkWrap: true,itemCount: _placeList.length,itemBuilder: (context,index) {
          return ListTile(
              title: Text(_placeList[index]["description"]),onTap: () {
                selectedItem = _placeList[index]["description"];
                print(selectedItem);
              });
        }),

在应用程序中构建的列表视图的图像:

enter image description here

解决方法

您可以在此处使用 def modify_json_file(json_file): with open(json_file,"r") as input_json: json_data = json.load(input_json) print("type of data: ",type(json_data)) for k,v in json_data.items(): print(k,v) print('\n'*2) temperature_settings = json_data["temperature_settings"] print("type of temperature_settings: ",type(temperature_settings)) print(temperature_settings["temperature_start"]) test_settings = json_data["test_settings"] temperature_settings["temperature_start"] = 99.9 new_settings = [] new_settings.append(test_settings) new_settings.append(temperature_settings) with open(json_file,"w") as input_json: json_data = json.dump(new_settings,input_json) print('\n'*25) modify_json_file("file6.json")``` 条件。最初ifselectedItem,所以null是可见的,一旦选择了一个项目,它就不是空的,所以我们隐藏了ListView。确保在您的 ListView 方法中使用 setState。一个简单的演示是

onTap

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...