创建了一个Stateful小部件,但无法设置state()



构建第一个flutter应用程序,在实现此类时遇到一些问题

我很确定它是一个Stateful Widget,我已经创建了一个构建方法,所以它应该是createState((的实现,但我仍然在类名上收到这个错误。由于这个错误,我无法设置State((一个全局列表,我正在添加到.

以下错误:

缺少"StatefulWidget.createState"的具体实现。请尝试实现缺失的方法,或者使类抽象。

class TransactionSubmission extends StatefulWidget {
final controllerForNumPad = NumpadController(format: NumpadFormat.CURRENCY);
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Submit your transaction!"),
),
body: Container(
//padding: EdgeInsets.all(0.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.all(50.0),
child: NumpadText(
controller: controllerForNumPad,
style: TextStyle(fontSize: 50))),
Expanded(
child: Numpad(
buttonColor: Colors.blue,
controller: controllerForNumPad,
buttonTextSize: 35)),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: RaisedButton(
padding: const EdgeInsets.all(10.0),
color: Colors.blue,
onPressed: () {
//String temp = controllerForNumPad.formattedString;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
ReportsPage()));
},
child: Text("Reports",
style: TextStyle(fontSize: 25)))),
SizedBox(
width: 250,
child: RaisedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ReportsPage()));
ReportsPage._key.currentState
.setTodo(Transaction(total: controllerForNumPad.formattedString));
setState(() {
});
controllerForNumPad.clear();
},
textColor: Colors.white,
padding: const EdgeInsets.all(10.0),
color: Colors.blue,
child:
Text("Submit", style: TextStyle(fontSize: 25))))
])
],
),
));
}
}

有状态小部件是一个类似于无状态小部件的抽象类。在有状态小部件的情况下,您必须覆盖createState方法,而不是构建方法。您的构建逻辑应该在从createState实现返回的小部件状态类中。

有关更多详细信息,请阅读flutter小部件介绍。

最新更新