0

I want to implement an infinitely scrolling, lazy loading Tik-Tok like social feed using Flutter and auto_route that automatically updates the current navigation route every time I swipe to the next page.

I was planning on using auto_route's AutoTabsRouter.pageView for this purpose:

AutoTabsRouter.pageView(            
  routes: [            
    BooksTab(),            
    ProfileTab(),            
    SettingsTab(),            
  ],           
  builder: (context, child, _) {            
    final tabsRouter = AutoTabsRouter.of(context);      
    return Scaffold(            
      appBar: AppBar(            
        title: Text(context.topRoute.name),            
        leading: AutoLeadingButton()),            
        body: child,            
        bottomNavigationBar: BottomNavigationBar(                
          currentIndex: tabsRouter.activeIndex,                
          onTap: tabsRouter.setActiveIndex                
          items: [                
            BottomNavigationBarItem(label: 'Books',...),                
            BottomNavigationBarItem(label: 'Profile',...),                
            BottomNavigationBarItem(label: 'Settings',...),                
          ],                
        ),          
      ),            
    );
  },          
);          

The problem I'm facing is that AutoTabsRouter.pageView requires a predetermined number of routes (whereas I want to provide an itembuilder and dynamically load new pages based on an index).

Do any of you have an idea of how I can resolve this issue?

Martin Reindl
  • 989
  • 2
  • 15
  • 33
  • so you want your `routes` list to be infinite in length? – pskink May 27 '23 at 05:24
  • Yes. Basically I want the functionality of a standard PageView.builder, just with the route changing every time I move to the next page in the builder. – Martin Reindl May 27 '23 at 05:26
  • so try `routes: MyRoutes(),` where: `class MyRoutes extends ListBase { ...` , more here: https://api.flutter.dev/flutter/dart-collection/ListBase-class.html – pskink May 27 '23 at 05:28
  • Having thought this trough some more. I think even having an infinite list of routes isn't really ideal either. PageView.builder is basically just an iterator that provides indices and then builds a widget on top of those (with some scrolling and standard functionality wrapped on top). I guess what I need is an AutoTabsRouter that doesn't take any routes and can generate routes (and their respective pages) based on an index – Martin Reindl May 27 '23 at 05:40
  • this is what `ListBase` is doing in `[]` operator, it should work if `AutoTabsRouter` does not try to "read" all the items at once but instead reads them on demand - just override those 3 unimplemented methods from `ListBase` and check it out when `[]` operator is called (and with what index) – pskink May 27 '23 at 06:02

0 Answers0