[英]Flutter - In autocomplete search location - The argument type 'List<String>?' can't be assigned to the parameter type 'List<String>'
When I'm run autocomplete search location using firebase_google_place library and use as per document implementation that time I got below error on run time.当我使用 firebase_google_place 库运行自动完成搜索位置并按照文档实现使用时,我在运行时遇到以下错误。
The argument type 'List?'参数类型“列表?” can't be assigned to the parameter type 'List' because 'List?'
不能分配给参数类型“List”,因为“List?” is nullable and 'List' isn't.
可以为空,而 'List' 不是。
Just before you do something with the List you got from firebase_google_places, check if the list you is null:就在您对从 firebase_google_places 获得的列表执行某些操作之前,请检查您的列表是否为空:
void main() {
List<String>? list = getList();
// check if null
if(list != null) {
checkList(list);
}
}
void checkList(List<String> list) {
print(list.first);
print(list.last);
}
List<String>? getList() {
return ["Test", "jdsgksa", "hsjgaiop"];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.