A BottomNavigationBar for nested routing and advanced features to improve user experience.

Related tags

UI navbar_router
Overview

navbar_router 0.1.2

Pub

This is the ultimate BottomNavigionBar created by considering the advanced use cases in real world applications. This widget handles the boilerplate code required to handle the below features with minimal code and hassle. All you need to do is specify the navbar menu items, routes and destinations and the rest will be taken care by the navbar_router.

Features

  • Smooth transitions when changing navbar destinations
  • Ability to push routes in the nested or root navigator
  • Notifies onBackButtonPress to handle app exits like a pro
  • Programmatically control state of bottom navbar from any part of widget tree e.g change index, hide/show bottom navbar, pop routes of a specific tab etc
  • persist state across bottom navbar tabs
  • Tapping the same navbar button pops to base route of nested navigator (same as instagram)
  • Switch the Navbar destination with animation

Heres a sample app built using this package to see how it works.

video demo of the sample app

navbar_route demo


This package will help you save atleast 50% lines of code in half the time required to implement the above features. Heres the same sample app without the package which requires around 800 lines of code.

Usage

Add to pubspec.yaml

  navbar_router: ^0.1.2

Example

class HomePage extends StatelessWidget {
  HomePage({Key? key}) : super(key: key);

  List<NavbarItem> items = [
    NavbarItem(Icons.home, 'Home', backgroundColor: colors[0]),
    NavbarItem(Icons.shopping_bag, 'Products', backgroundColor: colors[1]),
    NavbarItem(Icons.person, 'Me', backgroundColor: colors[2]),
  ];

  final Map<int, Map<String, Widget>> _routes = const {
    0: {
      '/': HomeFeeds(),
      FeedDetail.route: FeedDetail(),
    },
    1: {
      '/': ProductList(),
      ProductDetail.route: ProductDetail(),
    },
    2: {
      '/': UserProfile(),
      ProfileEdit.route: ProfileEdit(),
    },
  };

  @override
  Widget build(BuildContext context) {
    return NavbarRouter(
      errorBuilder: (context) {
        return const Center(child: Text('Error 404'));
      },
      onBackButtonPressed: (isExiting) {
        return isExiting;
      },
      destinationAnimationCurve: Curves.fastOutSlowIn,
      destinationAnimationDuration: 600,
      decoration:
          NavbarDecoration(navbarType: BottomNavigationBarType.shifting),
      destinations: [
        for (int i = 0; i < items.length; i++)
          DestinationRouter(
            navbarItem: items[i],
            destinations: [
              for (int j = 0; j < _routes[i]!.keys.length; j++)
                Destination(
                  route: _routes[i]!.keys.elementAt(j),
                  widget: _routes[i]!.values.elementAt(j),
                ),
            ],
            initialRoute: _routes[i]!.keys.first,
          ),
      ],
    );
  }
}

Features Breakdown

Fading between NavbarDestinations

You can have smooth Transitions between NavbarDestinations by setting the destinationAnimationCurve and destinationAnimationDuration properties.

defaults to

  destinationAnimationCurve: Curves.fastOutSlowIn,
  destinationAnimationDuration: 700,


Hide or show bottomNavigationBar

You can hide or show bottom navigationBar with a single line of code from anywhere in the widget tree. This allows you to handle useCases like scroll down to hide the navbar or hide the navbar on opening the drawer.

 NavbarNotifier.hideBottomNavBar = true;
Hide/show navbar on scroll Hide/show navbar on drawer open/close

Notify onBackButtonPress

navbar_router provides a onBackButtonPressed callback to intercept events from android back button. Giving you the ability to handle app exits (e.g you might want to implement double press back button to exit).

sample code implementing double press back button to exit

      onBackButtonPressed: (isExitingApp) {
        if (isExitingApp) {
          newTime = DateTime.now();
          int difference = newTime.difference(oldTime).inMilliseconds;
          oldTime = newTime;
          if (difference < 1000) {
            hideSnackBar();
            return isExitingApp;
          } else {
            showSnackBar();
            return false;
          }
        } else {
          return isExitingApp;
        }
      },


Docs

destinations: A List of DestinationRouter to show when the user taps the [NavbarItem]. Each DestinationRouter specifies a List of Destinations, initialRoute, and the navbarItem corresponding to that destination.

errorBuilder: A WidgetBuilder to show the user when the user tried to navigate to a route that does not exist in the [destinations].

decoration : The decoraton for Navbar has all the properties you would expect in a [BottomNavigationBar] to adjust the style of the Navbar.

onBackButtonPressed: A Function which defines whether it is the root Navigator or not if the method returns true then the Navigator is at the base of the navigator stack

destinationAnimationCurve: Curve for the destination animation when the user taps a navbar item. Defaults to Curves.fastOutSlowIn.

destinationAnimationDuration: The duration in milliseconds of the animation of the destination. Defaults to 700ms.

shouldPopToBaseRoute: A boolean which decides, whether the navbar should pop to the base route (pop all except first) when the current navbar is tapped while the route is deeply nested. This feature similar to Instagram's navigation bar defaults to true.

Curious how the navbar_router works?

Read more in a medium blog post for detailed explanation.

Contribution

Contributions are welcome! for more details on how to contribute, please see the contributing guide

Comments
  • [Android] Remember route history

    [Android] Remember route history

    copied from https://github.com/maheshmnj/navbar_router/issues/8

    For a better navigation/experience you might wanna consider adding some sort of visited tabs history in order to manage back button navigation for Android, apps like instagram,netflix ... handle the navigation history by keeping track of the order in which the user visits different tabs such a feature would be a perfect addition to your package, for inspiration take a look at the solution implemented in this one : ttps://pub.dev/packages/bottom_nav_layout#page-back-stack

    Feature Request fixed 
    opened by maheshmnj 3
  • Navbar should be able to add/remove tabs dynamically.

    Navbar should be able to add/remove tabs dynamically.

    Usecase Assume that a navbar has notifications tab, and the notifications tab needs to be shown only for loggedIn users and hidden for other users. In such cases we should be able to add or remove a tab conditionally.

    Feature Request fixed 
    opened by maheshmnj 2
  • Investigate offstage widgets

    Investigate offstage widgets

    Describe the bug Widgets that are offstage (not in view) should not gain in pointer or focus, One way to fix this is by using ignorePointer for !currentindex.

    Also when the focus is regained the state should remain unchanged.

    fixed 
    opened by maheshmnj 1
  • Pass arguments to widgets when Navigating via named routes

    Pass arguments to widgets when Navigating via named routes

    Figure out a way to pass arguments received in onGenerateRoute to respective widget

     onGeneratedRoute: (RouteSettings settings) {
          print(settings.arguments);
          WidgetBuilder? builder = widget.errorBuilder;
          final nestedLength = widget.destinations[i].length;
           for (int j = 0; j < nestedLength; j++) {
               if (widget.destinations[i][j].path == settings.name) {
                    builder = (BuildContext _) => widget.destinations[i][j].widget;
               }
           }
             return MaterialPageRoute(
                 builder: builder!, settings: settings);
     }),
    
    Feature Request 
    opened by maheshmnj 1
  • Improve Notch Shape

    Improve Notch Shape

    Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.

    List which issues are fixed by this PR. You must list at least one issue.

    Pre-launch Checklist

    • [X] I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • [X] I listed at least one issue that this PR fixes in the description above.
    • [X] I updated/added relevant documentation (doc comments with ///).
    • [X] I added new tests to check the change I am making, or this PR is [test-exempt].
    • [X] All existing and new tests are passing using flutter test

    If you need help, consider pinging the maintainer @maheshmnj

    opened by maheshmnj 0
  • Add support for new Navigationbar using `type: NavbartType.notched`

    Add support for new Navigationbar using `type: NavbartType.notched`

    This is a Work in progress to add more customizable NavigationBar

    Addresses: #8 ezgif com-gif-maker

    Pre-launch Checklist

    • [X] I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • [X] I listed at least one issue that this PR fixes in the description above.
    • [X] I updated/added relevant documentation (doc comments with ///).
    • [X] I added new tests to check the change I am making, or this PR is [test-exempt].
    • [X] All existing and new tests are passing using flutter test

    If you need help, consider pinging the maintainer @maheshmnj

    opened by maheshmnj 0
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced by 34% 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /example/web/icons/Icon-maskable-512.png | 20.51kb | 10.54kb | 48.61% | | /example/web/icons/Icon-maskable-192.png | 5.46kb | 3.66kb | 33.05% | | /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png | 14.45kb | 9.69kb | 32.93% | | /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png | 45.89kb | 31.58kb | 31.18% | | /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png | 1.40kb | 1.00kb | 28.62% | | /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png | 5.79kb | 4.27kb | 26.23% | | /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png | 3.20kb | 2.60kb | 18.77% | | | | | | | Total : | 96.70kb | 63.34kb | 34.50% |


    📝 docs | :octocat: repo | 🙋🏾 issues | 🏪 marketplace

    ~Imgbot - Part of Optimole family

    opened by imgbot[bot] 0
  • Can we have linkbased routing / deep linking and routeguard as a feature in the upcoming version?

    Can we have linkbased routing / deep linking and routeguard as a feature in the upcoming version?

    I am working on an app for my college where I want to pass url parameters in Notification Details route let's say the messageID, and i did try a few other options like auto route but they didn't have much flexibility in having different scaffolds for different pages with persistent bottom navigation bar which made me switch to this package.

    In my case I wish to send user to that particular notification with all the details on the on_click event which i guess would be possible with url parameters where i can pass the individual message id in the payload like notifications/notificationDetails:messageId, please correct me if I am wrong. Also, it would be really grateful if you can point me to the right resource as I am still new to flutter and have a lot more to explore

    As I already mentioned, I have tried go router and auto route but find them a bit complex when i wanted to have a different scaffold and persistent bottom navbar.

    Also, route guard feature would be a great addition too.

    Feature Request 
    opened by tushar4303 0
  • Elevation doesn't work on the NavBarDecoration

    Elevation doesn't work on the NavBarDecoration

    The background behind the navigation bar and the bottom nav bar are both white in my UI, which makes it really hard to notice the navbar's starting point and the elevation doesn't seem to work in order to add the shadow to the navbar

    Steps to reproduce the behavior:

    1. Changing value on the elevation property doesn't make ui shadow show up

    Expected behavior A shadow should have appeared at the top of the NavBar

    Screenshots

    Smartphone (please complete the following information):

    • Device: [Redmi Note 11]
    • OS: [Android ]
    • Version [12]
    bug flutter 
    opened by tushar4303 4
  • Support different NavigationBars to choose from

    Support different NavigationBars to choose from

    Hello and thank you for this great package full of highly requested features.

    For most modern apps one would need a custom BottomNavigationBar that would cater to his/her needs, unfortunately navbar_router doesn't support different navbar types for example let's say I wanna use this BottomNavigationBar from this package : https://pub.dev/packages/circular_bottom_navigation , it's currently impossible since navbar_router tries to build upon the default BottomNavigationBar which is quite limited , so maybe you would consider adding the ability to pass the whole BottomNavigationBar widget as parameter instead of a set of decoration parameters in order to lift this limitation ?

    Something like what this package provides would be awesome; https://pub.dev/packages/bottom_nav_layout#different-bottom-bars

    For a better navigation/experience you might wanna consider adding some sort of visited tabs history in order to manage back button navigation for Android, apps like instagram,netflix ... handle the navigation history by keeping track of the order in which the user visits different tabs such a feature would be a perfect addition to your package, for inspiration take a look at the solution implemented in this one : ttps://pub.dev/packages/bottom_nav_layout#page-back-stack

    Feature Request 
    opened by mohamoha6200 4
Owner
Mahesh Jamdade
Hacking Flutter every day.
Mahesh Jamdade
Tour guide App UI in Flutter Consist of Three Pages. First Screen is Splash Screen , Second is welcome screen routing to third Screen and Third screen consist of details , navigation, places, and responsive UI.

Tour Guide // Tourism App Ui in Flutter. Tour Guid App Ui in Flutter. Visit Website Features State Management Navigation Bar Responsive Design Hybrid

Habib ullah 2 Nov 14, 2022
Foody - Flutter project to display foods to clients and display charts and has a lot of features , two flutter apps : Android and Web

Foody Flutter project to display foods to the clients and use charts and use a lot of features to complete the process (HUGE APP) There two apps: Andr

ABDULKARIMALBAIK 1 Feb 7, 2022
A flutter package that contains a collection of icon decoration tools (i.e. gradient, opacity) and icon transition features with cool animation effects.

Advanced Icon A flutter package that contains a collection of icon decoration tools (i.e. gradient, opacity) and icon transition features with cool an

Ankit Mishra 8 Dec 24, 2021
A ecommerce app created in flutter implementing the features add to cart, total ,add, remove item and a login function

catalog A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if t

null 0 Nov 27, 2021
A set of high-level Flutter UI components and stand-alone widgets for easier implementation of most used UI features

A set of high-level Flutter UI components and stand-alone widgets for easier implementation of most used UI features

Evgeny Cherkasov 37 Jul 25, 2022
Crypto Trading UI - A Crypto Trading App with a modern UI using the latest features offered by Flutter

Crypto Trading UI This project is all about designing a Crypto Trading App with a modern UI using the latest features offered by Flutter. In a total o

DebugErrorX 7 Dec 28, 2022
A small attempt to make an e-commerce user interface in Flutter for Android and iOS.

Flutter ecommerce App A small attempt to make an e-commerce user interface in Flutter for Android and iOS. I developed this application just for learn

Md Tarikul Islam 615 Jan 3, 2023
🛍 A full E-commerce app with nice UI consists of on-boarding, login, sign-up, home, product details, cart and user profile.

?? A full E-commerce app with nice UI consists of on-boarding, login, sign-up, home, product details, cart and user profile.

null 56 Nov 27, 2022
Scratch card widget which temporarily hides content from user.

scratcher Scratch card widget which temporarily hides content from user. Features Android and iOS support Cover content with full color or custom imag

Kamil Rykowski 405 Dec 27, 2022
A wrapper to show a scroll to top prompt to the user on scrollable widgets.

flutter_scroll_to_top A wrapper to show a scroll to top prompt to the user on scrollable widgets. Installing Add the following dependency to your pubs

Naman Shergill 11 May 16, 2022
An user interface sample application of women apparel in flutter

Women Apparel Application An user interface sample application of women apparel in flutter. Project Created & Maintained By MultiQoS Pvt. Ltd. Demo Ap

MultiQoS 13 Sep 16, 2022
A flutter package to display a country, states, and cities. In addition it gives the possibility to select a list of countries, States and Cities depends on Selected, also you can search country, state, and city all around the world.

A flutter package to display a country, states, and cities. In addition it gives the possibility to select a list of countries, States and Cities depends on Selected, also you can search country, state, and city all around the world.

Altaf Razzaque 25 Dec 20, 2022
Instagram UI designed with Flutter; it is compatible and responsive with any type of Android and iOS devices.

instagram Instagram clone UI designed with Flutter; it is compatible and responsive with any type of Android and iOS devices . Getting Started This pr

Mustafa Nabavi 4 Oct 28, 2021
I am trying to teach Responsive Ui design. This video for Web and Mobile. This design is suitable for Desktop, Tab, and Mobile platforms.

before clone the GitHub repository please give a star on the repository. I am trying to teach Responsive Ui design. This video for Web and Mobile. Thi

Blackshadow Software Ltd 22 Sep 1, 2022
A set of interesting and fun UI components, animations and routes for Flutter.

すごい ・ Sugoi A set of interesting and fun UI components, animations and routes for Flutter. By Jay (Jeroen) Meijer. This project was bootstrapped by Ve

Jeroen Meijer (Jay) 5 Jan 22, 2022
A highly customisable Flutter widget for entering pin code. Suitable for use cases such as login and OTP.

pin_code_text_field It's a beautiful and highly customizable Flutter widget for entering pin code. Suitable for use cases such as login and OTP. Usage

Liew Jun Tung 309 Dec 28, 2022
Nice and clean Online Shop app UI by using #Flutter.

On our E-commerce app UI has two pages one for the product page which has a horizontal list of categories then a list of our products. Then on the details page, it shows the price and short description of the product with the Buy Now button. The best part of our E-commerce app is, each product has its own color which looks great.

Abu Anwar 1.7k Jan 3, 2023
A Splash screen with curved custom bottom sheet and dots indicator within it.

Pub.dev Curved Splash Screen A Splash screen with curved custom bottom sheet and dots indicator within it. You can add your custom splash screens acco

Hosain Mohamed 16 Dec 1, 2022
This Dart package offers developers a streamlined library of Flutter widgets, useful for expanding widgets and text views, when users interact with them.

This Dart package offers developers a streamlined library of Flutter widgets, useful for expanding widgets and text views, when users interact with them.

Jesús Rodríguez 44 Dec 6, 2022