flutter - 'List 类型的值' 不能分配给类型为 'Iterable 的变量'
问题描述
我不知道这是否发生在我切换到 Flutter 的 beta 通道之前,但我不明白为什么这是一个错误。列表是可迭代的,对吗?我从官方文档中获取了示例。
Iterable<int> example() {
Iterable<int> iterable = [1, 2, 3];
return iterable;
}
VSCode 用红色下划线标记列表,告诉我:
A value of type 'List<int>' can't be assigned to a variable of type 'Iterable<int>'.
Try changing the type of the variable, or casting the right-hand type to 'Iterable<int>'. dart(invalid_assignment)
解决方案
我不知道是什么问题,但我尝试从 VSCode 中删除 Flutter 和 Dart 扩展,重新启动整个计算机并再次安装它们(按此顺序),现在相同的代码可以工作了!
正如BeefPapa在评论中所说,代码是绝对正确的。
谁知道发生了什么。
推荐阅读
- c++ - 如何重新解释强制转换数组,这样做是否安全?
- python - 使用 numpy 扩展尺寸后无法返回 PIL Image
- elasticsearch - ElasticSearch - 获取多次出现
- ruby - 使用 Nokogiri 插入未转义的 URL
- batch-file - 从同级目录移动文件
- java - 按字母顺序将节点插入到链表中
- android - 如何使用 Jenkins、github 和 android studio
- c - 如何用优先表证明 C 后缀增量运算符的合理性?
- react-native - 遍历 onLayout 调用以向 FlatList 的 getItemLayout 提供项目的行高时出现问题
- typescript - 如何为打字稿类的抽象方法定义模板?