繁体   English   中英

Dart: ambiguous_set_or_map_literal_both

[英]Dart : ambiguous_set_or_map_literal_both

嗨,我是 flutter 移动应用程序开发的新手,并在 udemy 上学习课程。 我被困在一个地方,教练可以用地图和文字变量创建变量,而在我的编辑器中我收到这个错误,上面写着

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 官方文档,但无法解决。 请如果有人可以帮助我。 谢谢。

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}, 
    },
  ];

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

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

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

这应该工作

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}
      ]
    },
  ];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM