简体   繁体   中英

I am using BottomNavigationBar to navigate to diff SliverList. I observe that It does not retain to the last row that I scrolled. How can I fix this?

class _HomeState extends State<Home> {
  int _currentIndex = 0;
  final List<Widget> _children = [Profile(), ServiceRequestList()];
  void _onTap(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: _children[_currentIndex],
        bottomNavigationBar: BottomNavigationBar(
          onTap: _onTap,
          currentIndex: _currentIndex,
          items: [
            BottomNavigationBarItem(
              icon: Icon(Icons.account_circle),
              title: Text('Profile'),
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.assignment),
              title: Text('Service'),
            ),
          ],
        ));
  }
}

I am using BottomNavigationBar to navigate to diff SliverList. I observe that It does not retain to the last row that I scrolled. How can fix this?

PageStorageKey is what you are looking for!

Within your Profile page and ServiceRequestList page's SliverList widget, set a unique page storage key like the following:

SliverList(
  key: PageStorageKey("somethingUnique"),
)

PageStorageKey works with any widget that has a scrolling region.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM