赞
踩
with AutomaticKeepAliveClientMixin
并且
@override // TODO: implement wantKeepAlive bool get wantKeepAlive => true;
后,发现页面任然不能保持其状态
-------------
加上
super.build(context);后任然无效
------------------------------------------
后来发现,原来是因为数据定义在widget中了,每次widget中的数据都会被初始化
把数据定义在state中,问题解决!
- class MyPage extends StatefulWidget {
- @override
- _MyPageState createState() => _MyPageState();
- }
-
-
- class _MyPageState extends State<MyPage>with AutomaticKeepAliveClientMixin {
- List items = List();
- //数据要定义在这里,页面保持状态才能生效!
- UserInfo userInfo = UserInfo();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。