我总共有 10 个小时的编码经验,所以请原谅我的无知。在 TODO 下,它应该是(这是教程显示的内容)return null; 而不是 throw UnimplementedError();
这是我所拥有的副本。
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!");
},
),
],
),
),
);
}
}
答案 0 :(得分:1)
这应该可以解决它!
class MyQuizApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
_MyQuizAppState createState() => _MyQuizAppState();
}
}