使用 BottomTabNavigator 在 2 个屏幕之间导航时页面从 begin 开始

Page started at begin when navigate between 2 screen using BottomTabNavigator

我是 Flutter 的新人。我开始了一个关于社交媒体的新项目。我使用 BottomTabNavigation 将主屏幕导航到通知屏幕。现在的问题是,当我在主页上显示提要时,我向下滚动了很多 post。假设我在 post 50 号。现在,当我单击通知并再次单击主页时,它从头开始。我需要在每个主屏幕上将滚动条保持在之前的位置。

这是我将一页导航到另一页的代码。

class _DefaultLayoutWidgetState extends State<DefaultLayoutWidget> {
  final List<Map<String, dynamic>> _pages = [
    {'page': PostScreen(), 'title': 'SelfieCorner'},
    {'page': NotificationScreen(), 'title': 'Notifications'}
  ];

  int _curruntIndex = 0;

  void handleTapEvent(inx) {
    setState(() {
      _curruntIndex = inx;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PostAppBarWidget(),
      body: _pages[_curruntIndex]['page'],
      bottomNavigationBar: BottomNavigationBar(
        onTap: (index) => handleTapEvent(index),
        currentIndex: _curruntIndex,
        items: [
          BottomNavigationBarItem(
            icon: Icon(
              Icons.home,
            ),
            title: Text('Home'),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.notifications,
            ),
            title: Text('Notifications'),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.lock,
            ),
            title: Text('Profile'),
          )
        ],
      ),
    );
  }
}

考虑像这样使用 IndexedStack。它会在移动到另一个时保存前一个 widgetstate

body: IndexedStack(.....),
      bottomNavigationBar: BottomNavigationBar(
        onTap: (index) => handleTapEvent(index),
        currentIndex: _curruntIndex,
        items: [
          BottomNavigationBarItem(
            icon: Icon(
              Icons.home,
            ),
            title: Text('Home'),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.notifications,
            ),
            title: Text('Notifications'),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.lock,
            ),
            title: Text('Profile'),
          )
        ],
      ),