0

I have such a structure of my UI:

TabBarView(children:[_Fragment1,_Fragment2...])

_Fragment1 shows files of my user and I need to implement navigation between folders with backstack. I have listview in my _Fragment1 and when item clicked and item is a folder folder's files should be shown(only files fragment is changed). I tried make it like this but it fails:

onTap: () => (_filesList[index].isFolder)
              ? Navigator.push(context, MaterialPageRoute(builder: (_) => _FilesListView(_filesList[index].children)))
              : null,

Is there a solution as easy as fragments in android? Maybe there are some packages that can help to make something like this.

Ilya Maximencko
  • 411
  • 2
  • 15

1 Answers1

1

I found the solution here https://stackoverflow.com/a/52247870/10260006 and here Use nested Navigator with WillPopScope in Flutter but what I want to add that I needed to specify only root named route and ongenerateroute for it like this

WillPopScope(
            onWillPop: () async {
              navigatorKey.currentState.maybePop();
              return false;
            },
            child: Navigator(
              key: navigatorKey,
              initialRoute: '/',
              onGenerateRoute: (settings) {
                return (settings.name == '/')
                    ? MaterialPageRoute(
                        builder: (context) => _FilesListView(filesList.where((file) => file.isShared == false).toList()),
                        settings: settings)
                    : null;
              },
            ),
          ),

and further you can use just Navigator.of(context).push

Ilya Maximencko
  • 411
  • 2
  • 15