gpt4 book ai didi

dart - Flutter:无法将类型为 lib1::Object 的值分配给类型为 lib2::Object 的变量

转载 作者:IT老高 更新时间:2023-10-28 12:34:04 25 4
gpt4 key购买 nike

在尝试编译这段代码时:

import 'package:flutter/material.dart';
import 'package:startup_namer/misc/Constants.dart';
import 'package:startup_namer/ui/question_text.dart';
import '../utils/question.dart';
import '../utils/quiz.dart';
import '../ui/answer_button.dart';
import '../ui/correct_wrong_overlay.dart';

class QuizPage extends StatefulWidget {
@override
State createState() => new QuizPageState();
}

//States are mutable
class QuizPageState extends State<QuizPage> {

static List<Question> quizQuestions = [
new Question("5 * 5 = 25", true),
new Question("4 + 2 = 6", true),
new Question("4 + 2 = 7", false),
new Question("Computers don't use energy", false),
new Question("B is after A in the alphabet", false),
];

Question currentQuestion;
Quiz quiz = new Quiz(quizQuestions);

String questionText;
int questionNumber;
bool isCorrect, overlayShouldBeVisible = false;


@override
void initState() {
super.initState();
this.currentQuestion = this.quiz.nextQuestion;
this.questionText = this.currentQuestion.aQuestion;
this.questionNumber = this.quiz.questionNumber;
}

@override
Widget build(BuildContext context) {
return new Stack(
fit: StackFit.expand,
children: <Widget>[
//Container for tons of stuff (Main page essentially)
new Column(
children: <Widget>[
new AnswerButton(true, () => testMe(true)),
new QuestionText(this.questionText, this.questionNumber),
new AnswerButton(false, () => testMe(false)),
], //<Widget>[]
), //Column
(this.overlayShouldBeVisible) ? new CorrectWrongOverlay(true) : new Container()
] //<Widget>[]
); //Stack
}
}

void testMe(bool isTrue){
if(isTrue){
print("it is true, huzzah!");
} else {
print("it is false, :(");
}
}

我收到此错误:

Error: A value of type 'dart.core::List<#lib1::Question>' can't be assigned to a variable of type 'dart.core::List<#lib2::Question>'.

我关注 this教程系列并已根据其存储库检查了代码,但无法查看导致此问题的原因。

如果没有其他不明确的 Question 类与之冲突,为什么我会看到此转换错误?

最佳答案

事实证明,问题与如何在顶部声明导入有关。

我没有在其他地方看到过这个,所以我会在这里回答这个问题。从这些更新我的导入:

import '../utils/question.dart';
import '../utils/quiz.dart';
import '../ui/answer_button.dart';
import '../ui/correct_wrong_overlay.dart';

对这些

import 'package:startup_namer/utils/question.dart';
import 'package:startup_namer/utils/quiz.dart';
import 'package:startup_namer/ui/answer_button.dart';
import 'package:startup_namer/ui/correct_wrong_overlay.dart';

我在哪里使用完整的包声明而不是速记版本似乎解决了这个问题。

关于dart - Flutter:无法将类型为 lib1::Object 的值分配给类型为 lib2::Object 的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50913869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com