flutter之保持页面状态

2019-12-18  本文已影响0人  不泯iOS

要想保持该页面的状态那么创建该页面的时候就需要混入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(
      ......
    );
  }
}

上一篇下一篇

猜你喜欢

热点阅读