- 无状态组件不允许写事件
- 有状态组件由两个类组成, 一个是StatefulWidget ,一个是state类
- state类持有Widget的生命周期
- setState() 更改数据
```javascript
class HomeContent extends StatefulWidget {
@override
State
createState() { // TODO: implement createState return _HomeContnetState(); } }
class _HomeContnetState extends State { int _conuter = 1; @override Widget build(BuildContext context) { return Container( child: RaisedButton( child: Text(“$_conuter”), onPressed: addCount, )); } void addCount() { setState(() { _conuter++; }); } } ```