首先在需要保持页面状态的页面混入AutomaticKeepAliveClientMixin
然后重写wantKeepAlive方法返回true
class HomeState extends State<HomePage> with AutomaticKeepAliveClientMixin {
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
...
有页面保持效果的有pageView和IndexedStack
body: IndexedStack(
index: _currentIndex,
children: tabBodies,
),