提问人:Ashwani Verma 提问时间:3/7/2023 最后编辑:Frank van PuffelenAshwani Verma 更新时间:3/7/2023 访问量:37
我正在尝试使用Firestore中的数据创建一个typeAhead表单字段,但无法获取列表
I am trying to create a typeAhead form Field With the data from Firestore but Not able to fetch the list
问:
我正在尝试创建一个 typeAhead 表单字段,它可以建议在下面输入的城市名称是小部件
Widget buildCity() {
return FutureBuilder<Object>(
future: firestoreLocationGet,
builder: (context, snapshot) {
if (!snapshot.hasData) return Container();
return TypeAheadFormField<String?>(
onSuggestionSelected: (String? suggestion) {},
itemBuilder: (context, String? suggestion) => ListTile(
title: Text(suggestion!),
),
suggestionsCallback: ((pattern) async {
return LocationData.getsuggestion(pattern);
}));
});
}
这是我从Firestore获取数据的类
final firestoreLocationGet =
FirebaseFirestore.instance.collection("location").get();
class LocationData {
static List<String> cities = [];
static void fetchCities() async {
await firestoreLocationGet.then((querySnapshot) {
cities =
querySnapshot.docs.map((doc) => doc['Location'] as String).toList();
});
}
static List<String> city = cities.map((e) => e).toList();
static List<String> getsuggestion(String query) {
return city
.where((city) => city.toLowerCase().contains(query.toLowerCase()))
.toList();
}
}
在表格中输入时,我得到“未找到项目”
这是数据库的屏幕截图 数据库的屏幕截图
这是应用程序中显示的错误屏幕截图 应用程序中显示的错误
答: 暂无答案
评论