Flutter--tabBarView切换页面 防止页面重绘

需要注意三点:

1.被重绘的tab页要 混入AutomaticKeepAliveClientMixin

//with    混入  类似多重继承
class ListFrgtPageState extends State
    with AutomaticKeepAliveClientMixin {

2.实现wantKeepAlive方法 ,返回值改成true

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

3.build中加入 super.build(context);

@override
Widget build(BuildContext context) {
  super.build(context);
  // TODO: implement build

你可能感兴趣的:(Flutter,防止页面重绘)