当前位置:   article > 正文

Flutter 保持页面状态不生效原因_flutter automatickeepaliveclientmixin不生效

flutter automatickeepaliveclientmixin不生效

with  AutomaticKeepAliveClientMixin

并且 

@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;

后,发现页面任然不能保持其状态

-------------

加上 

super.build(context);后任然无效

------------------------------------------

后来发现,原来是因为数据定义在widget中了,每次widget中的数据都会被初始化

把数据定义在state中,问题解决!

 

  1. class MyPage extends StatefulWidget {
  2. @override
  3. _MyPageState createState() => _MyPageState();
  4. }
  5. class _MyPageState extends State<MyPage>with AutomaticKeepAliveClientMixin {
  6. List items = List();
  7. //数据要定义在这里,页面保持状态才能生效!
  8. UserInfo userInfo = UserInfo();

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/307813
推荐阅读
相关标签
  

闽ICP备14008679号