[英]The argument type 'List<dynamic>' can't be assigned to the parameter type 'List<Map<String, Object>>'
here is basically the entire code which is related to the error I suppose!!这里基本上是与我想的错误相关的整个代码! I am new to programming as well as Flutter, I tried to splitting the code into widgets so my code be cleaner.
我是编程和 Flutter 的新手,我尝试将代码拆分为小部件,以便我的代码更干净。 that's where I got stuck by this message: The argument type 'List' can't be assigned to the parameter type 'List<Map<String, Object>>'.
这就是我被这条消息卡住的地方:无法将参数类型“List”分配给参数类型“List<Map<String, Object>>”。 I hope it's clear now to be checked.
我希望现在可以检查清楚。 thanks!
谢谢!
my Main.dart code我的 Main.dart 代码
import 'package:flutter/material.dart';
import 'package:quiz2/ui/question.dart';
import 'package:quiz2/ui/quiz.dart';
import 'package:quiz2/ui/result.dart';
import './ui/answer.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int _index = 0;
final List _questions = const [
{
'questionText': 'who\'s your favorite football player? ',
'Answers': ['Cristiano', ' Messi', 'Mbappe', 'Benzema']
},
{
'questionText': 'who\'s your favorite Ping Pong player',
'Answers': [
'Noshad Alamian',
'Nima Alamian',
'Aria Amiri',
'Matin Lotfollah Nassabi'
]
},
{
'questionText': 'what\'s your favorite color',
'Answers': ['Grey', 'Black', 'Green', 'Red']
},
{
'questionText': 'what\'s your favorite football club',
'Answers': ['Real Madrid', 'Barcelona', 'Manchester United', 'Liverpool']
}
];
void _answerQuestion() {
if (_index < _questions.length) {
debugPrint('we have more questions');
} else {
debugPrint('no more questions');
}
setState(() {
_index = _index + 1;
});
debugPrint('answered !!');
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
backgroundColor: Color.fromARGB(255, 115, 147, 163),
title: Text('Quiz App'),
centerTitle: true,
),
backgroundColor: Colors.blueGrey.shade600,
body: Container(
child: _index < _questions.length
? Quiz(
index: _index,
answerQuestion: _answerQuestion,
questions: _questions)
: Result()),
),
);
}
}
Problem might be with Flutter not properly defining type of your initialized list because you are creating type List (without any further specified generic type).问题可能在于 Flutter 没有正确定义初始化列表的类型,因为您正在创建类型 List(没有任何进一步指定的泛型类型)。
Change from从改变
final List _questions = const [ ...
To至
final _questions = const <Map<String,Object>>[ ...
Or或者
final List<Map<String,Object>> _questions = const [ ...
Should do the trick应该做的伎俩
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.