参数类型"列表<dynamic>"不能分配给参数类型'List<Map<String, Object>>'



这里基本上是与错误有关的整个代码我想!!我是新的编程以及Flutter,我试图把代码分成小部件,让我的代码更干净。这就是我被这条消息卡住的地方:参数类型'List'不能分配给参数类型'List<String,>>'。我希望现在可以检查清楚了。谢谢!

我的主。飞镖代码

测试。飞镖代码

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()),
),
);
}
}

问题可能是Flutter没有正确定义初始化列表的类型,因为您正在创建类型列表(没有任何进一步指定的泛型类型)。

从改变

final List _questions = const [ ...

final _questions = const <Map<String,Object>>[ ...

final List<Map<String,Object>> _questions = const [ ...

应该能成功

最新更新