尝试在列表中获取数据,我得到一个错误:命名参数未定义



我学会了扑动和使用测验游戏教程。问题是,然后我试图在列表中获得问题列表,我的调试控制台返回我undefined_named_parameter。我尝试了不同的解决方案,但我仍然有同样的问题

我的代码

import 'package:flutter/animation.dart';
import 'package:get/get.dart';
import 'package:quizz_app/models/question.dart';
//we use get pckage for our state management
class QuestionController extends GetxController
with SingleGetTickerProviderMixin {
late AnimationController _animationController;
late Animation _animation;
Animation get animation => _animation;
// ignore: prefer_final_fields
Iterable _question = sampleData
.map((question) => Question(
id: question['id'],
answer: question['answer_id'],
question: question['question'],
options: question['option']))
.toList();
@override
void onInit() {
_animationController =
AnimationController(duration: const Duration(seconds: 60), vsync: this);
_animation = Tween(begin: 1.0, end: 0.0).animate(_animationController)
..addListener(() {
//update like setstate
update();
});
_animationController.forward();
super.onInit();
}
}

这是我的问题列表

class Question {
final int id, answer;
final String question;
final List<String> options;
Question(this.id, this.answer, this.question, this.options);
}
const List sampleData = [
{
"id": 1,
"question":
"Flutter is an open-source UI software development kit created by ______",
"options": ['Apple', 'Google', 'Facebook', 'Microsoft'],
"answer_index": 1,
},
{
"id": 2,
"question": "When google release Flutter.",
"options": ['Jun 2017', 'Jun 2017', 'May 2017', 'May 2018'],
"answer_index": 2,
},
{
"id": 3,
"question": "A memory location that holds a single letter or number.",
"options": ['Double', 'Int', 'Char', 'Word'],
"answer_index": 2,
},
{
"id": 4,
"question": "What command do you use to output data to the screen?",
"options": ['Cin', 'Count>>', 'Cout', 'Output>>'],
"answer_index": 2,
},
];
question: question[question]

Iterable _question = sampleData
.map((question) => Question(
id: question['id'],
answer: question['answer_id'],
question: question[question], // This
options: question['option']))
.toList();

应该

question: question['question']

相关内容

  • 没有找到相关文章

最新更新