Playful and customizable bottom navigation bar for Flutter

Overview

rolling_nav_bar

A bottom nav bar with layout inspired by this design and with heavily customizable animations, colors, and shapes.

Getting Started

To get started, place your RollingNavBar in the bottomNavigationCar slot of a Scaffold, wrapped in a widget that provides max height. For example:

Scaffold(
  bottomNavigationBar: Container(
    height: 95,
    child: RollingNavBar(
      // nav items
    ),
  )
);

Alternatively, you can place it directly using a Stack:

Scaffold(
  body: Stack(
    children: <Widget>[
      Positioned(
        bottom: 0,
        height: 95,
        width: MediaQuery.of(context).size.width,
        child: RollingNavBar(
          // nav items
        ),
      )
    ]
  )
);

Customization

RollingNavBar is heavily customizable and works with 3, 4, or 5 navigation elements. Each element is also fully customizable through the two primary ways to specify child navigation elements.

The first option is to pass a list of IconData objects, along with optional lists of Color objects.

RollingNavBar.iconData(
  iconData: <IconData>[
    Icons.home,
    Icons.people,
    Icons.settings,
  ],
  indicatorColors: <Color>[
    Colors.red,
    Colors.yellow,
    Colors.blue,
  ],
)

The second option is to provide a widget builder, though this comes with some loss of helpful active state management.

RollingNavBar.builder(
  builder: (context, index, info, update) {
    // The `iconData` constructor handles all active state management,
    // but this constructor, as it deals with completed widgets, must
    // assume that you have already made all relevant considerations.
    var textStyle = index == info.nextIndex
      ? TextStyle(color: Colors.white)
      : TextStyle(color: Colors.grey);
    return Text('${index + 1}', style: style);
  },
  indicatorColors: <Color>[
    Colors.red,
    Colors.yellow,
    Colors.blue,
  ],
  numChildren: 3,
)

Animation Types

RollingNavBar comes with four animation flavors for the active indicator's transition from tab to tab.

The first animation type is the namesake: AnimationType.roll:

RollingNavBar.iconData(
  animationCurve: Curves.easeOut,  // `easeOut` (the default) is recommended here
  animationType: AnimationType.roll,
  baseAnimationSpeed: 200, // milliseconds
  iconData: <IconData>[
    ...
  ],
)

Roll Example


Note: For the roll animation type, your supplied animation speed is a multiplier considered against the distance the indicator must travel. This ensures a constant speed of travel no matter where the user clicks.


The second animation type is a fade-and-reappear effect:

RollingNavBar.iconData(
  animationCurve: Curves.linear, // `linear` is recommended for `shrinkOutIn`
  animationType: AnimationType.shrinkOutIn,
  baseAnimationSpeed: 500, // slower animations look nicer for `shrinkOutIn`
  iconData: <IconData>[
    ...
  ],
)

Shrink-out-in Example


Note: For the shinkOutIn animation type, your supplied animation speed is constant, since the active indicator never travels the intermediate distance.


The third animation type is a spinning version of fade-and-reappear:

RollingNavBar.iconData(
  animationCurve: Curves.linear, // `linear` is recommended for `spinOutIn`
  animationType: AnimationType.spinOutIn,
  baseAnimationSpeed: 500, // slower animations look nicer for `spinOutIn`
  iconData: <IconData>[
    ...
  ],
)

Spin-out-in Example


Note: Like with shinkOutIn, for the spinOutIn animation type, your supplied animation speed is constant, since the active indicator never travels the intermediate distance.


The final animation flavor is a non-animation:

RollingNavBar.iconData(
  // `animationCurve` and `baseAnimationSpeed` are ignored
  animationType: AnimationType.snap,
  iconData: <IconData>[
    ...
  ],
)

Snap Example


Hooking into the animation

In the demo, the background of the larger hexagon matches the background of the nav bar hexagon. To achieve this and similar effects, two callbacks, onTap and onAnimate, are available. onAnimate can be particularly helpful for syncing visual effects elsewhere in your app with nav bar progress.

Tab Item Text

If using the iconData constructor, you are also able to pass a list of widgets to render as text below inactive icons.

RollingNavBar.iconData(
  // A list of length one implies the same color for all icons
  iconColors: <Color>[
    Colors.grey[800],
  ],
  iconData: <IconData>[
    Icons.home,
    Icons.friends,
    Icons.settings,
  ],
  iconText: <Widget>[
    Text('Home', style: TextStyle(color: Colors.grey, fontSize: 12)),
    Text('Friends', style: TextStyle(color: Colors.grey, fontSize: 12)),
    Text('Settings', style: TextStyle(color: Colors.grey, fontSize: 12)),
  ]
)

Icon Text Example

Icon badges

Using the Badges library, RollingNavBar is able to easily expose nav bar badges. The following works with either constructor.

RollingNavBar.iconData(
  badges: <Widget>[
    Text('1', style: TextStyle(Colors.white)),
    Text('1', style: TextStyle(Colors.white)),
    null,
    null,
    Text('1', style: TextStyle(Colors.white)),
  ],
  iconData: <IconData>[
    Icons.home,
    Icons.friends,
    Icons.account,
    Icons.chat,
    Icons.settings,
  ],

Badges Example

Driving Navigation Bar Changes

You can programmatically change the active navigation bar tab by passing a new activeIndex to the RollingNavBar widget. However, there are two steps to successfully keeping everything in sync.

class _MyAppState extends State<MyApp> {
  int activeIndex;

  /// Handler that responds to navigation events (likely derived
  /// from user clicks) and keeps the parent in sync.
  void _onTap(int index) {
    setState(() {
      activeIndex = index;
    });
  }

  /// Handler for when you want to programmatically change
  /// the active index. Calling `setState()` here causes
  /// Flutter to re-render the tree, which `RollingNavBar`
  /// responds to by running its normal animation.
  ///
  /// Note: This is an example function that you can define
  /// and call wherever you like. That is why it is not passed
  /// to `RollingNavBar.iconData` in the `build` method.
  void changeActiveIndex(int index) {
    setState((){
      activeIndex = index;
    });
  }

  Widget build(BuildContext context) {
    return RollingNavBar.iconData(
      activeIndex: activeIndex,
      iconData: iconData,
      onTap: _onTap,
    );
  }
}
You might also like...

Flutter circle bottom bar by animation

Flutter circle bottom bar by animation

Animation circle bottom bar Flutter circle bottom bar by animation how to use: 1. add dependencies to pubspec.yaml: circle_bottombar: ^1.1.1 2. create

Oct 29, 2022

Expandable bottom app bar widget for Flutter SDK

Expandable bottom app bar widget for Flutter SDK

Expandable bottom app bar widget for Flutter SDK

Dec 28, 2022

Notched Bottom Tab Bar Example using Flutter Framework

Notched Bottom Tab Bar Example using Flutter Framework

bottom_tab_bar Notched Bottom Tab Bar Example using Flutter Framework Getting Started Flutter tutorial explaining how to create a notched shaped botto

Dec 6, 2022

Doctor Consultation App in Flutter containing splash screen on boarding screen Routing state management Dash board Bottom navigation Decorated Drawer and Doctors Screen in the last.

Doctor Consultation App in Flutter containing splash screen on boarding screen  Routing  state management Dash board Bottom navigation Decorated Drawer and Doctors Screen in the last.

Online doctor Consultation App UI in Flutter Doctor Consultation App UI in Flutter Visit Website Features State Management Navigation Bar Responsive D

Jan 1, 2023

A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

r_scan A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your iss

Nov 11, 2022

Starlight search bar - Starlight search bar with flutter

Starlight search bar - Starlight search bar with flutter

starlight_search_bar If you find the easiest way to search your item, this is fo

Apr 20, 2022

This is a JazzCash UI clone ( Modern Wallet App in Pakistan), implementing modern app bar animmation. One can take a concept of making app bar with animation.

jazzcash_ui This is a JazzCash UI clone ( Modern Wallet App in Pakistan), implementing modern app bar animmation. One can take a concept of making app

Nov 27, 2022

Flutter-FFNavigationBar - Configurable navigation bar for Flutter

Flutter-FFNavigationBar - Configurable navigation bar for Flutter

ff_navigation_bar A highly configurable navigation bar with emphasis for the selected item. Add dependency dependencies: ff_navigation_bar: ^0.1.5

Sep 22, 2022

Flutter Navigation - all types of navigation in flutter run main.tabBar.dart to see tabBar, and run main.dart to see the otheres

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

Jan 1, 2022
Comments
  • Error in index

    Error in index

    hello sir,

    how are you?

    I need to thank you for this amazing package, but I have a problem,

    when I convert the language app to Arabic (right to left language) I faced some error in index,

    when I click the first tab from the right, the first one from the left appears in some color.

    like the photo below :

    https://i.ibb.co/SwFnFV2/Screenshot-20200718-142514.jpg

    and when I click the second from right, the second from the left appears in some color.

    this is my code :

    RollingNavBar.iconData(
                        activeBadgeColors: <Color>[
                              Colors.white,
                            ],
                            activeIndex: widget._selectedIndex,
                            animationCurve: Curves.linear,
                            animationType: AnimationType.roll,
                            baseAnimationSpeed: 900,
                            badges: <Widget>[
                              null,
                              cart.basketItems.length > 0
                                  ? Text("${cart.basketItems.length}",
                                  style: TextStyle(
                                      color: widget._selectedIndex != 1
                                          ? Theme_Information.Color_1
                                          : Theme_Information.Color_5))
                                  : null,
                              null,
                              null,
                            ],
                            iconData: iconData,
                            iconColors: <Color>[Colors.grey[800]],
                            iconText: iconText,
                            indicatorColors: indicatorColors,
                            iconSize: 25,
                            indicatorRadius: scaledHeight(context, 30),
                            onAnimate: _onAnimate,
                            onTap: _onTap,
                          ),
    
    
    

    please help me.

    opened by faress123 4
  • Move call to onTap callback to onPressed

    Move call to onTap callback to onPressed

    Thanks for this package!

    I believe there's a small bug: the call to the widget.onTap callback should be in onPressed rather than in _setActive, since _setActive is also called from didUpdateWidget, which I don't think should call the onTap callback. (This leads to problems when onTap calls setState, for example, which then gets triggered during a rebuild.)

    Hopefully this PR handles it all correctly.

    opened by olof-dev 3
  • Navigate to another tab programmatically

    Navigate to another tab programmatically

    I want to navigate to another tab programmatically For example i have integer of _selectedIndex like

    int _selectedIndex = 0;
    RollingNavBar.iconData(
      animationCurve: Curves.fastOutSlowIn,
      animationType: AnimationType.roll,
      baseAnimationSpeed: 200,
      iconData: <IconData>[
        Icons.home,
        Icons.trending_down,
        Icons.favorite,
        Icons.person,
      ],
      iconColors: <Color>[Colors.grey[600]],
      iconText: <Widget>[
        Text('Home', style: TextStyle(color: Colors.grey, fontSize: 12)),
        Text('Test', style: TextStyle(color: Colors.grey, fontSize: 12)),
        Text('Test', style: TextStyle(color: Colors.grey, fontSize: 12)),
        Text('Account', style: TextStyle(color: Colors.grey, fontSize: 12)),
      ],
      indicatorColors: <Color>[
        Strings.purpleSolid,
        Color(0xFFF29414),
        Color(0xFFff0000),
        Color(0xFF064987),
      ],
      iconSize: 27,
      indicatorRadius: 50,
      activeIndex: _selectedIndex,
      onTap: (index) {
        setState(() {
          _selectedIndex = index;
        });
      },
    ),
    

    Now if i try to change value of _selectedIndex it doesn't switch to another tab but my IndexedStack goes to specified tab.

    IndexedStack(
      index: _selectedIndex,
      children: <Widget>[
        SafeArea(child: homeWidget()),
        SafeArea(child: secondWidget()),
        SafeArea(child: thirdWidget()),
        SafeArea(child: accountWidget()),
      ],
    )
    

    This library should listen to index value if it changes it goes to another tab automatically.

    opened by sukhcha-in 3
Owner
Craig Labenz
Craig Labenz
Custom bottom bar - A bottom tool bar that can be swiped left or right to expose more tools.

custom_bottom_bar A bottom tool bar that can be swiped left or right to expose more tools. usage Create your custom bottom bars with up to four custom

null 4 Jan 26, 2020
A custom bottom navigation bar with box animation for flutter

A custom bottom navigation bar with box animation. This is inspired from some of the earlier designs, but in a more simplified and yet exiting way. De

SHIVAM SONI 1 Jul 31, 2022
New trick on how to create your own custom icons in flutter with bottom bar navigation

Customized Bottom Navigation Bar in Flutter | Tech With Sam Customized Bottom Navigation Bar in Flutter - Watch on youtube ✌   App Preview App Screens

Samuel Adekunle 10 Oct 26, 2022
This is repository for Spin Circle Bottom Navigation Bar Package for Flutter

Spin Circle Bottom Bar An easy to implement Spin Circle Bottom Navigation Bar for Flutter Applications. Current Features Initial Release for Spin Circ

Paras Jain 79 Dec 22, 2022
simple flutter bottom navigation bar widget

bmnav A very flexible Flutter implementation of the Bottom Navigation Bar. Get Started Add bmanv to your pubspec.yaml file: dependencies: bmnav: ^0.

Edwin 21 Oct 8, 2022
A 3D Bottom Navigation Bar in Flutter

flip_box_bar A 3D BottomNavigationBar inspired by Dribbble design by Dannniel [https://dribbble.com/shots/4811135-Tab-Bar-Cube-Interaction]. Demo Exam

Deven Joshi 258 Nov 19, 2022
Custom Shaped Bottom Navigation Bar in Flutter

CustomShapedBottomBar Custom Shaped Bottom Navigation Bar in Flutter **Usage: ** Add CustomPaint Widget to use this Painter class like this: C

Shraddha Sojitra 5 May 6, 2022
Bottom navigation bar with sliding clip effect.

Sliding Clipped Nav Bar Design Credit Toolbar icons animation by Cuberto How to use? API reference barItems → List<BarItem> List of bar items that sho

Watery Desert 55 Dec 3, 2022
A fancy animated bottom navigation bar 💫.

Stacky_bottom_nav_bar A fancy animated bottom navigation bar. Preview Default Light Mode Default Dark Mode ⚠️ IMPORTANT: when adding this widget don’t

null 5 Oct 23, 2022
Animation nav bar - Flutter Animated Navigation Bar

Flutter Animated Navigation Bar Getting Started This project is a starting point

Sudesh Nishshanka Bandara 23 Dec 30, 2022