Home > Blockchain >  Flutter: Getting error in List when combining
Flutter: Getting error in List when combining

Time:02-10

Iam trying to shorten these steps

List<String> questionText = [
    'You can lead a cow down stairs but not up stairs.',
];
List<bool> questionAnswer = [
    false,

Combining these 2 List to single in another class but getting error in 'Question'

class Question {
  String questionText;
  bool questionAnswer;

  Question({required String q, required bool a}) {
    questionText = q;
    questionAnswer = a;
  }
}

//Error Here Error Img

CodePudding user response:

It's written like this in dart.

class Question {
  String questionText;
  bool questionAnswer;

  Question({required this.questionText, required this.questionAnswer});
}

Check: https://dart.dev/guides/language/language-tour#constructors

Create an object like so:

Question question = Question(
   questionText: "You can lead a cow down stairs but not upstairs",
   questionAnswer: false,
);
  • Related