Preserve Widget State in PageView while enabling Navigation

后端 未结 1 703
被撕碎了的回忆
被撕碎了的回忆 2021-02-06 14:20

I have a rather complex situation in a Flutter App. I have a Home screen that is a swipable PageView,that displays 3 child Widgets : Calendar, Messages, Profile.

My issu

1条回答
  •  半阙折子戏
    2021-02-06 15:13

    From the documentation on AutomaticKeepAliveClientMixin:

    /// A mixin with convenience methods for clients of [AutomaticKeepAlive]. Used with [State] subclasses.

    /// Subclasses must implement [wantKeepAlive], and their [build] methods must call super.build (the return value will always return null, and should be ignored).

    So in your code, before you return the Scaffold just call super.build:

      Widget build(BuildContext context) {
        super.build(context);
        return Scaffold(...);
      }
    

    0 讨论(0)
提交回复
热议问题