【问题标题】:How to maintain state of pages in TabBarView in Flutter?Flutter中如何维护TabBarView中的页面状态?
【发布时间】:2020-05-02 06:37:54
【问题描述】:

我使用 TabBarView 作为底部导航栏的页面持有者,而不是索引堆栈。但这确实会在每次更改选项卡时刷新页面。状态不被维护。怎么办?

【问题讨论】:

  • 您的代码似乎有问题。可以加点代码吗?

标签: flutter flutter-layout flutter-test flutter-navigation flutter-appbar


【解决方案1】:

使用AutomaticKeepAliveClientMixinflutter.dev

class _SampleScaffoldSate extends State<SampleScaffold> with AutomaticKeepAliveClientMixin {

  // ... other code

  @override
  bool get wantKeepAlive => true;

}

【讨论】:

    猜你喜欢
    • 2021-10-17
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 2019-12-02
    • 1970-01-01
    • 2019-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多