【发布时间】:2019-12-22 09:40:15
【问题描述】:
我目前正在学习 Flutter。我试图深入研究 Flutter Widget 的生命周期,我想知道为什么 StatefulWidget 是这样写的:
class Example extends StatefulWidget {
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
// initState
// setState
// ...
@override
Widget build(BuildContext build) {
...
}
}
但不是:
class Example extends StatefulWidget {
// initState
// setState
// ...
@override
Widget build(BuildContext build) {
...
}
}
我认为后者使来源变得简单。但我不知道他们为什么使用前一种风格?
【问题讨论】:
-
感谢 Mazin 先生的编辑