dart – Flutter:lib1 :: Object类型的值不能分配给lib2 :: Object类型的变量

前端之家收集整理的这篇文章主要介绍了dart – Flutter:lib1 :: Object类型的值不能分配给lib2 :: Object类型的变量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在尝试编译此代码时:

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",new Question("4 + 2 = 7",false),new Question("Computers don't use energy",new Question("B is after A in the alphabet",];

    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教程系列,并检查了他们的存储库的代码,但我无法看到导致此问题的原因.

如果没有其他模糊的问题类与之冲突,为什么我会看到这个投射错误

解决方法

事实证明,这个问题与如何宣布进口最高有关.

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

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';

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

猜你在找的Flutter相关文章