What's the usage of three dots (…) in dart List?

廉价感情. 提交于 2021-01-18 12:11:20

问题


I have my code written like this but it gives an error saying:

Error: A value of type 'List' can't be assigned to a variable of type 'Widget'.

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

回答1:


Dart 2.3 introduce Spread operator (…)

Reference link : 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]



回答2:


I've figured out my issue. My flutter SDK wasn't upgraded. Ran flutter doctor command and sorted out the missing updates. And the syntax seems to be working fine now.

flutter upgrade

Dart version (required) >= 2.3

Restart IDE (if the problem persists)



来源:https://stackoverflow.com/questions/57900901/whats-the-usage-of-three-dots-in-dart-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!