тип ‘_compactlink HashSet’ не является подтипом типа «Список» в приведенном типе

#flutter #flutter-android

Вопрос:

Я сталкиваюсь с этой ошибкой, она работает идеально, но не показывает вывода и отображает следующую ошибку типа «_compactlink-хэш-набор» не является подтипом типа «Список» в типе приведенного флаттера

 import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:quizler/Question.dart';
import 'Question.dart';

void main() => runApp(quizler());

class quizler extends StatelessWidget {
  const quizler({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.grey.shade900,
        body: SafeArea(
          child: QuizzPage(),
        ),
      ),
    );
  }
}

class QuizzPage extends StatefulWidget {
  const QuizzPage({Key? key}) : super(key: key);

  @override
  _QuizzPageState createState() => _QuizzPageState();
}

class _QuizzPageState extends State<QuizzPage> {
  List<Widget> scoreKeeper = [];
 List<Question> questionBank={
   Question(q: 'Moon Color is gray',a:false),
   Question(q: 'Independence Day of pakistan was 1947',a:true),
   Question(q: 'Tesla was the owner of Starlink company',a:false),
 } as List<Question> ;
  int questionNumber = 0;
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        Expanded(
          flex: 5,
          child: Padding(
            padding: EdgeInsets.all(15.0),
            child: Center(
              child: Text(
                questionBank[questionNumber].questionText,
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontSize: 25.0,
                  color: Colors.white,
                ),
              ),
            ),
          ),
        ),
        Expanded(
          child: Padding(
            padding: EdgeInsets.all(20.0),
            child: FlatButton(
              textColor: Colors.white,
              color: Colors.green,
              onPressed: () {
                bool correctAnswer = questionBank[questionNumber].questionAnswer;
                if (correctAnswer == true) {
                  setState(() {
                    questionNumber  ;
                    scoreKeeper.add(
                      Icon(Icons.check, color: Colors.green),
                    );
                  });
                } else {
                  setState(() {
                    questionNumber  ;
                    scoreKeeper.add(
                      Icon(
                        Icons.check,
                        color: Colors.red,
                      ),
                    );
                  });
                }
              },
              child: Text(
                'True',
              ),
            ),
          ),
        ),
        Expanded(
          child: Padding(
            padding: EdgeInsets.all(20.0),
            child: FlatButton(
              textColor: Colors.white,
              color: Colors.red,
              onPressed: () {
                bool correctAnswer = questionBank[questionNumber].questionAnswer;
                if (correctAnswer == false) {
                  setState(
                    () {
                      questionNumber  ;
                      scoreKeeper.add(
                        Icon(Icons.check, color: Colors.green),
                      );
                    },);
                }
                else{
                  setState(
                        () {
                      questionNumber  ;
                      scoreKeeper.add(
                        Icon(Icons.check, color: Colors.red),
                      );
                    },);
                }
              },
              child: Text(
                'False',
              ),
            ),
          ),
        ),
        Row(
          children: scoreKeeper,
        ),
      ],
    );
  }
}

**Here is the Question.dart code**
    > Question.dart
    
    class Question{   late String questionText;   late bool
    questionAnswer;  Question({required String q, required bool a})   { 
    questionText=q;    questionAnswer=a;   } }'
 

Следующий _КастЕррор был сброшен при создании MediaQuery(MediaQueryData(размер: Размер(360.0, 736.0), форматирование устройства: 3.0, масштабирование текста: 1.0, Четкость платформы: Яркость.темнота, заполнение: окантовка.ноль, отображение: окантовка.ноль, просмотр: окантовка.ноль, просмотр: окантовка. ноль, всегда используется 24 часа Формат: ложь, Доступная навигация: ложь, Высокая скорость: ложь, Отключаемые объекты: ложь, инвертные цвета: ложь, полужирный текст: ложь, режим навигации: традиционный)):
тип «_CompactLinkedHashSet» не является подтипом типа «Список» в приведенном типе

Ответ №1:

Измените его на этот:

 List<Question> questionBank=[
   Question(q: 'Moon Color is gray',a:false),
   Question(q: 'Independence Day of pakistan was 1947',a:true),
   Question(q: 'Tesla was the owner of Starlink company',a:false),
 ]
 

Используйте квадратные скобки. Или измените свое определение на:

 Set<Question> questionBank = { ....etc };