londonappbrewery / quizzler-flutter-challenge-final

Completed version of the Quizzler project in the Complete Flutter Bootcamp
https://www.appbrewery.co
63 stars 137 forks source link

getQuestionText returns me null #8

Closed NoNatio closed 4 years ago

NoNatio commented 4 years ago

Hi, I don't know what I did wrong, but I can't pull the text from the class Question, the app crashes and it says because "A non-null String must be provided to a text widget". I've been spinning around it and I realized that, if I just try to print in the Dartpad the text for the first Question, it returns null, I guess that's the root of my trouble but I don't know exactly what to do to fix it. The analysis returns no error. Any help is welcome. Thanks.

void main() { print(questionBank[0].questionText); }

class Question { String questionText; bool questionAnswer;

Question(String questionText, bool questionAnswer); }

List questionBank = [ Question('You can lead a cow down stairs but not up stairs.', false), Question('Approximately one quarter of human bones are in the feet.', true), Question('A slug\'s blood is green.', true), Question('Some cats are actually allergic to humans', true), Question('Buzz Aldrin\'s mother\'s maiden name was \'Moon.', true), Question(It is illegal to pee in the Ocean in Portugal.', true), Question('No piece of square dry paper can be folded in half more than 7 times.', false), Question('In London, UK, if you happen to die in the House of Parliament, you are technically entitled to a state funeral, because the building is considered too sacred a place.', true), Question(questionText: 'The loudest sound produced by any animal is 188 decibels. That animal is the African Elephant.', false), Question('The total surface area of two human lungs is approximately 70 square metres.', true), Question('Google was originally called \"Backrub\".', true), Question('Chocolate affects a dog\'s heart and nervous system; a few ounces are enough to kill a small dog.', true), Question('In West Virginia, USA, if you accidentally hit an animal with your car, you are free to take it home to eat.', true), ];

NoNatio commented 4 years ago

This was the problem,

Question(String questionText, bool questionAnswer);

should always have this format if you don't wanna use the square brackets way:

Question(String q, bool a) {questionText=q; questionAnswe=a);

Anyway, check out the "Dart Class constructors" lesson, it explains it all and more.