首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Dart : ambiguous_set_or_map_literal_both

Dart : ambiguous_set_or_map_literal_both
EN

Stack Overflow用户
提问于 2020-05-25 22:07:35
回答 1查看 1.2K关注 0票数 2

嗨,我是新的颤振移动应用程序开发和遵循的课程上的udemy。我被困在一个地方,老师可以用映射和文字变量来创建变量,而在我的编辑器中,我得到了这样的错误:

代码语言:javascript
复制
This literal contains both 'Map' and 'Iterable' spreads, which makes it impossible to determine whether the literal is a map or a set. Try removing or changing some of the elements so that all of the elements are consistent

我和教官一起检查了很多次代码,也检查了Dart的官方文档,但是无法解决。如果有人能帮我的话。谢谢。

代码语言:javascript
复制
final _questions = const [
    {
      'questionText':
          'Who is the current president of The United Stated of America?',
      'answers': [
        {'text': 'Donald Trump', 'score': 10},
        {'text': 'Ram Nath Kovind', 'score': -10},
        {'text': 'Pedro Sánchez', 'score': -10},
      ],
    },
    {
      'questionText': 'Which of these is the currency used in Japan?',
      'answers': {'text': 'Ringgit', 'score': -10},
      {'text': 'Yuan', 'score': -10},
      {'text': 'Yen', 'score': 10},
    },
    {
      'questionText': 'Which of these is the capital of Spain?',
      'answers': {'text': 'Madrid', 'score': 10},
      {'text': 'Washington DC', 'score': -10},
      {'text': 'Moscow', 'score': -10},
    },
    {
      'questionText': 'Which one is the language of Israel?',
      'answers': {'text': 'Persian', 'score': -10},
      {'text': 'Hebrew', 'score': 10},
      {'text': 'Turkish', 'score': -10},
    },
    {
      'questionText': 'Who among these was the Missile Man of India?',
      'answers': {'text': 'Pranab Mukherjee', 'score': -10},
      {'text': 'Sir APJ Abdul Kalam', 'score': 10},
      {'text': 'Bhagat Singh', 'score': -10}, 
    },
  ];

这是包含一些问题集的变量。代码截图

检查屏幕截图以获得更多错误信息。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-25 22:23:21

第一个元素中的answers是一个数组,在下一个元素中语法是错误的。

这应该能行

代码语言:javascript
复制
final _questions = const [
    {
      'questionText':
          'Who is the current president of The United Stated of America?',
      'answers': [
        {'text': 'Donald Trump', 'score': 10},
        {'text': 'Ram Nath Kovind', 'score': -10},
        {'text': 'Pedro Sánchez', 'score': -10},
      ],
    },
    {
      'questionText': 'Which of these is the currency used in Japan?',
      'answers': [
        {'text': 'Ringgit', 'score': -10},
        {'text': 'Yuan', 'score': -10},
        {'text': 'Yen', 'score': 10}
      ]
    },
    {
      'questionText': 'Which of these is the capital of Spain?',
      'answers': [
        {'text': 'Madrid', 'score': 10},
        {'text': 'Washington DC', 'score': -10},
        {'text': 'Moscow', 'score': -10}
      ]
    },
    {
      'questionText': 'Which one is the language of Israel?',
      'answers': [
        {'text': 'Persian', 'score': -10},
        {'text': 'Hebrew', 'score': 10},
        {'text': 'Turkish', 'score': -10}
      ]
    },
    {
      'questionText': 'Who among these was the Missile Man of India?',
      'answers': [
        {'text': 'Pranab Mukherjee', 'score': -10},
        {'text': 'Sir APJ Abdul Kalam', 'score': 10},
        {'text': 'Bhagat Singh', 'score': -10}
      ]
    },
  ];
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62011504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档