J.S.C.
J.S.C.

Reputation: 11

(FLUTTER) I'm getting this problem: throw UnimplementedError();

I have a total of 10 hours of coding experience so spare my ignorance. Under the TODO it's supposed to be (this is what the tutorial shows) return null; instead of throw UnimplementedError();

This is a copy of what I have.

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


class MyQuizApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    throw UnimplementedError();
  }
}

class MyQuizAppState extends State<MyQuizApp> {
  var questionIndex = 0;

  void answerQuestion() {
    questionIndex = questionIndex + 1;
    print(questionIndex);
  }

  @override
  Widget build(BuildContext context) {
    var questions = [
      "What\'s your favorite color?",
      "What\'s your favorite fruit?",
    ];
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Personality Quiz"),
        ),
        body: Column(
          children: [
            Text(questions[questionIndex]),
            RaisedButton(
              child: Text("Answer 1"),
              onPressed: answerQuestion,
            ),
            RaisedButton(
              child: Text("Answer 2"),
              onPressed: () => print("Answer chosen!"),
            ),
            RaisedButton(
              child: Text("Answer 3"),
              onPressed: () {
                print("Answer chosen!");
              },
            ),
          ],
        ),
      ),
    );
  }
}

Upvotes: 0

Views: 821

Answers (1)

Adithaz
Adithaz

Reputation: 419

This should fix it!

class MyQuizApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    _MyQuizAppState createState() => _MyQuizAppState();
  }
}

Upvotes: 1

Related Questions