在使用 TabBar,TabBarView 时候,flutter 默认在切换 tab 时候 widget 的 initState 又会被调用一次,怎么解决这个问题呢
1 state 混入 AutomaticKeepAliveClientMixin
2 state 添加成员属性
@override
bool get wantKeepAlive => true;
3 在 build 方法中添加
super.build(context);
其他方案
1 IndexedStack
2 Stack + OffStage + TickerMode
网友评论