嗨,我是新的颤振移动应用程序开发和遵循的课程上的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},
},
];这是包含一些问题集的变量。代码截图
检查屏幕截图以获得更多错误信息。
发布于 2020-05-25 22:23:21
第一个元素中的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}
]
},
];https://stackoverflow.com/questions/62011504
复制相似问题