flutter - 试图在列表中获取数据,我收到一个错误:未定义命名参数
问题描述
我学会了颤振并使用问答游戏教程。然后我试图在一个列表中获取问题列表,我的调试控制台返回我未定义的名称参数。我尝试了不同的解决方案,但我仍然有同样的问题
我的代码
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']
推荐阅读
- python - 我怎样才能得到硒中的文字?
- python - 如果从另一列满足字符串条件,则在 Pandas 中执行计算
- c++ - 如何将数组中的值设置为数独游戏的单元格对象
- html - 如何将填充保留在 contenteditable div 中,就像保留在 textarea 中一样?
- bash - 自动推送的脚本有问题
- javascript - 兑换 20% 代金券后在 JS 中重新计算价格
- reactjs - 缺少依赖项:React 中的“调度”
- multithreading - Rust 多线程 HTTP 请求,从响应中获取所有数据?
- spring-boot - 在 Spring Boot 中使用自定义注释
- typescript - 类型-graphql。字符串、布尔值和数字的联合类型失败