简体   繁体   English

Flutter - 在自动完成搜索位置 - 参数类型 &#39;List<String> ?&#39; 不能分配给参数类型“列表”<String> &#39;

[英]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' 不是。

  • 'List' is from 'dart:core'. “列表”来自“dart:core”。 types: widget.types,类型:widget.types,

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.

相关问题 参数类型 &#39;List<string> &#39; 不能分配给参数类型 &#39;String&#39; - The argument type 'List<string>' can't be assigned to the parameter type 'String' 参数类型“String”不能分配给参数类型“Uri”。 Flutter - The argument type 'String' can't be assigned to the parameter type 'Uri'. Flutter Flutter 错误:无法将参数类型“Color Function(String)”分配给参数类型“dynamic Function(dynamic)” - Flutter error: The argument type 'Color Function(String)' can't be assigned to the parameter type 'dynamic Function(dynamic)' 参数类型'响应<dynamic> ' 不能分配给 Flutter 上的参数类型 'String'</dynamic> - The argument type 'Response<dynamic>' can't be assigned to the parameter type 'String' on Flutter Flutter(dart) 错误:无法将参数类型分配给参数类型 'dynamic Function(List<student> ?)'</student> - Flutter(dart) error: The argument type can't be assigned to the parameter type 'dynamic Function(List<Student>?)' 参数类型'列表<dynamic> ' 不能分配给参数类型 'List<value*> *', flutter 库比蒂诺日期选择器内 form_bloc</value*></dynamic> - The argument type 'List<dynamic>' can't be assigned to the parameter type 'List<Value*>*' , flutter cupertino date picker inside form_bloc PlatformFile selectedFile 类型:PlatformFile 参数类型“字符串?” 无法分配给参数类型“String” - PlatformFile selectedFile Type: PlatformFile The argument type 'String?' can't be assigned to the parameter type 'String' 当我在 flutter 2.2.2 中使用地图时出现错误。(无法将参数类型“对象?”分配给参数类型“字符串”。) - error shows up when i use maps in flutter 2.2.2 .(The argument type 'Object?' can't be assigned to the parameter type 'String'.) Flutter - 参数类型 &#39;Complexity/*1*/&#39; 不能分配给参数类型 &#39;Complexity/*2*/ - Flutter - argument type 'Complexity/*1*/' can't be assigned to the parameter type 'Complexity/*2*/ 参数类型 SearchBar 不能分配给 flutter 中的参数类型 Widget - The argument type SearchBar can't be assigned to the parameter type Widget in flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM