如何在Flutter中维护TabBarView中页面的状态?

问题描述 投票:0回答:1

我已经使用TabBarView作为BottomNavigationBar的页面保持器,而不是索引堆栈。但这确实会在每次更改选项卡时刷新页面。状态未维护。该怎么办?

flutter flutter-layout flutter-test flutter-navigation flutter-appbar
1个回答
0
投票

使用AutomaticKeepAliveClientMixin flutter.dev

class _SampleScaffoldSate extends State<SampleScaffold> with AutomaticKeepAliveClientMixin {

  // ... other code

  @override
  bool get wantKeepAlive => true;

}
© www.soinside.com 2019 - 2024. All rights reserved.