How to create nested Navigation in Flutter?

0

Basically there will be a main "part" in my App after logging in which only contains a custom Bottom Navigation Bar for now. Now, there are multiple Navigation Items in it, which should display different screens for every one of them like home_screen, map_screen, search_screen and so on, which then can hold an App Bar just like Instagram, Facebook and so on.

So in conclusion every Bottom Navigation Item should have its own screen (and detail screens) with an App Bar each for now. With that I would like to be able to keep track of the last shown screen. So for example if I click on a button in map_screen that navigates me to a new screen and I decide to switch to the search_screen for a moment, I would like to see the exact same screen again when switching back to map_screen.

Hopefully it is clear what I am trying to achieve.

I thought that maybe there is a way to have one file/class to keep track of all the navigation / routing stuff, wether authentication screens or main screens.

tabs_screen (which is shown mainly):

import 'package:flutter/material.dart';
import 'package:bubble_bottom_bar/bubble_bottom_bar.dart';

class TabsScreen extends StatefulWidget {

  @override
  _TabsScreenState createState() => _TabsScreenState();
}

class _TabsScreenState extends State<TabsScreen> {

  int currentIndex;

  @override
  void initState() {
    super.initState();

    currentIndex = 0;
  }

  void changeScreen(int index) {
    setState(() {
      currentIndex = index;
    });
  }

  @override 
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xFFFFFFFF),

      floatingActionButton: FloatingActionButton(
        onPressed: () {},
        child: Icon(Icons.add),
        backgroundColor: Colors.red,
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
      bottomNavigationBar: BubbleBottomBar(
        hasNotch: true,
        fabLocation: BubbleBottomBarFabLocation.end,
        opacity: .2,
        currentIndex: currentIndex,
        onTap: changeScreen,
        elevation: 8,
        items: <BubbleBottomBarItem>[
          BubbleBottomBarItem(
            backgroundColor: Colors.red,
            icon: Icon(
              Icons.dashboard,
              color: Colors.black,
            ),
            activeIcon: Icon(
              Icons.dashboard,
              color: Colors.red,
            ),
            title: Text("Start")
          ),
          BubbleBottomBarItem(
            backgroundColor: Colors.deepPurple,
            icon: Icon(
              Icons.access_time,
              color: Colors.black,
            ),
            activeIcon: Icon(
              Icons.access_time,
              color: Colors.deepPurple,
            ),
            title: Text("Logs")
          ),
          BubbleBottomBarItem(
            backgroundColor: Colors.indigo,
            icon: Icon(
              Icons.folder_open,
              color: Colors.black,
            ),
            activeIcon: Icon(
              Icons.folder_open,
              color: Colors.indigo,
            ),
            title: Text("Folders")
          ),
          BubbleBottomBarItem(
            backgroundColor: Colors.green,
            icon: Icon(
              Icons.menu,
              color: Colors.black,
            ),
            activeIcon: Icon(
              Icons.menu,
              color: Colors.green,
            ),
            title: Text("Profil")
          )
        ],
      ),
    );
  }
}
android
ios
flutter
dart
navigation
asked on Stack Overflow Mar 23, 2020 by Florian Leeser

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0