要想保持该页面的状态那么创建该页面的时候就需要混入AutomaticKeepAliveClientMixin这个widget,
并且在该类中添加一行代码:bool get wantKeepAlive => true;
使用举例
class MallPage extends StatefulWidget {
@override
MallPageState createState() => MallPageState();
}
class MallPageState extends State<MallPage> with AutomaticKeepAliveClientMixin {
bool get wantKeepAlive => true;
@override
Widget build(BuildContext context) {
// TODO: implement build
return new MaterialApp(
......
);
}
}
网友评论