flutter - 飞镖列表中三个点(...)的用途是什么?
问题描述
我的代码是这样写的,但它给出了一个错误消息:
错误:不能将“List”类型的值分配给“Widget”类型的变量。
Column(
children: [
Question(
questions[_questionIndex]['questionText'],
),
...(questions[_questionIndex]['answers'] as List<String>)
.map((answer) {
return Answer(_answerQuestion, answer);
}).toList()
],
)
解决方案
Dart 2.3 引入了扩展运算符 (…)
参考链接:https ://medium.com/flutter-community/whats-new-in-dart-2-3-1a7050e2408d
var a = [0,1,2,3,4];
var b = [6,7,8,9];
var c = [...a,5,...b];
print(c); // prints: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
推荐阅读
- typescript - 无法以简单的方式在打字稿文件中定义方法
- java - POJO序列化问题
- java - Firebase 服务器密钥隐藏
- revit-api - 在链接和元素之间添加维度
- java - 正则表达式查找最少 3 个字符,后跟一个点和空格
- ios - 在 Flutter audio_service 中指定背景音频控件
- python - 编写 python 脚本以从用户输入列表中散点图 x 和 y 坐标
- python - 如何在 mysql 数据库中的 fetchone() 中对输出列表进行交互
- conv-neural-network - 与 RGB 图像的卷积 - RGB 过滤器具有哪些值?
- python-3.x - 类型错误:forward() 缺少 1 个必需的位置参数:在实施 Grad CAM 时为“x”