首页 > 解决方案 > 飞镖列表中三个点(...)的用途是什么?

问题描述

我的代码是这样写的,但它给出了一个错误消息:

错误:不能将“List”类型的值分配给“Widget”类型的变量。

Column(
  children: [
    Question(
      questions[_questionIndex]['questionText'],
    ),
    ...(questions[_questionIndex]['answers'] as List<String>)
        .map((answer) {
      return Answer(_answerQuestion, answer);
    }).toList()
  ],
)

标签: flutterdart

解决方案


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]

推荐阅读