Giter Club home page Giter Club logo

bottom_navy_bar's Introduction

Pub Awesome Flutter Widget Tests

Latest compatibility result for Stable channel Latest compatibility result for Beta channel Latest compatibility result for Dev channel



BottomNavyBar

A beautiful and animated bottom navigation. The navigation bar uses your current theme, but you are free to customize it.

Preview PageView
FanBottomNavyBar Gif Fix Gif

Customization (Optional)

BottomNavyBar

  • iconSize - the item icon's size
  • items - navigation items, required more than one item and less than six
  • selectedIndex - the current item index. Use this to change the selected item. Defaults to zero
  • onItemSelected - required to listen when an item is tapped it provides the selected item's index
  • backgroundColor - the navigation bar's background color
  • showElevation - if false the appBar's elevation will be removed
  • mainAxisAlignment - use this property to change the horizontal alignment of the items. It is mostly used when you have ony two items and you want to center the items
  • curve - param to customize the item change's animation
  • containerHeight - changes the Navigation Bar's height

BottomNavyBarItem

  • icon - the icon of this item
  • title - the text that will appear next to the icon when this item is selected
  • activeColor - the active item's background and text color
  • inactiveColor - the inactive item's icon color
  • textAlign - property to change the alignment of the item title

Getting Started

Add the dependency in pubspec.yaml:

dependencies:
  ...
  bottom_navy_bar: ^6.0.0

Basic Usage

Adding the widget

bottomNavigationBar: BottomNavyBar(
   selectedIndex: _selectedIndex,
   showElevation: true, // use this to remove appBar's elevation
   onItemSelected: (index) => setState(() {
              _selectedIndex = index;
              _pageController.animateToPage(index,
                  duration: Duration(milliseconds: 300), curve: Curves.ease);
    }),
   items: [
     BottomNavyBarItem(
       icon: Icon(Icons.apps),
       title: Text('Home'),
       activeColor: Colors.red,
     ),
     BottomNavyBarItem(
         icon: Icon(Icons.people),
         title: Text('Users'),
         activeColor: Colors.purpleAccent
     ),
     BottomNavyBarItem(
         icon: Icon(Icons.message),
         title: Text('Messages'),
         activeColor: Colors.pink
     ),
     BottomNavyBarItem(
         icon: Icon(Icons.settings),
         title: Text('Settings'),
         activeColor: Colors.blue
     ),
   ],
)

Use with PageView and PageController

class _MyHomePageState extends State<MyHomePage> {

  int _currentIndex = 0;
  PageController _pageController;

  @override
  void initState() {
    super.initState();
    _pageController = PageController();
  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Bottom Nav Bar")),
      body: SizedBox.expand(
        child: PageView(
          controller: _pageController,
          onPageChanged: (index) {
            setState(() => _currentIndex = index);
          },
          children: <Widget>[
            Container(color: Colors.blueGrey,),
            Container(color: Colors.red,),
            Container(color: Colors.green,),
            Container(color: Colors.blue,),
          ],
        ),
      ),
      bottomNavigationBar: BottomNavyBar(
        selectedIndex: _currentIndex,
        onItemSelected: (index) {
          setState(() => _currentIndex = index);
          _pageController.jumpToPage(index);
        },
        items: <BottomNavyBarItem>[
          BottomNavyBarItem(
            title: Text('Item One'),
            icon: Icon(Icons.home)
          ),
          BottomNavyBarItem(
            title: Text('Item Two'),
            icon: Icon(Icons.apps)
          ),
          BottomNavyBarItem(
            title: Text('Item Three'),
            icon: Icon(Icons.chat_bubble)
          ),
          BottomNavyBarItem(
            title: Text('Item Four'),
            icon: Icon(Icons.settings)
          ),
        ],
      ),
    );
  }
}

Contributions

Contributions of any kind are more than welcome! Feel free to fork and improve in any way you want, make a pull request, or open an issue. See CONTRIBUTING.md for more info on how to contribute to this project.

License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.

bottom_navy_bar's People

Contributors

antonio-pedro99 avatar danxcvii avatar georgeherby avatar lukevenediger avatar mohamed0017 avatar nohli avatar notsfsssf avatar pedromassango avatar trietbui85 avatar victoruvarov avatar xazin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bottom_navy_bar's Issues

Fixed on top

Hey. I was wondering if there’s a way to keep it locked in place even when we’ve changed pages (pages that are not listed in the items array). I know the default BottomNavigationBar accept a type and it can be a type of fixed and was wondering if BottomNavyBar also has something similar. I really need it to always be there, in every single page.

I honestly love this widget, thanks a lot for making it

Routes

Does this work with routes, if so, how?
thanks,

bLOC pattern configuration

can we have the index click function as an event in bloc pattern? Or do you just use stream builder and pagination if you want one of the views to load items from firestore

Item Max

BottomNavyBarItem max is 5, how to use more than 5 item?

Error selectedIndex

BottomNavyBar(
   selectedIndex: _selectedIndex,
   showElevation: true, // use this to remove appBar's elevation
   onItemSelected: (index) => setState(() {
              _selectedIndex = index;
              _pageController.animateToPage(index,
                  duration: Duration(milliseconds: 300), curve: Curves.ease);
    }),

BottomNavyBar has a currentIndex not selectedIndex.
bottom_navy_bar: ^3.0.0
Flutter 1.7.8

Can't set default active item before Tap

I'd like to have an item(Tab) to be selected on the first launch, but it only reacts to a tap.
index is 0 by default, but it awaits for a tap, all tabs have inactive view by default.

ImageIcon

Hello, as my icons are customized I can only access using icon: ImageIcon(images/ icon.png), in BottomNavigationBarItem I can, but in your package only accept Icon in icon (icon: Icon(Icons.add)
How to solve?

Swiping through pages work but Changing page through nav bar doesnt bar

Below is the code in my main.dart file, note that swiping behaviour works but the logic of pageController doesn't work.

class _MyHomePageState extends State<MyHomePage> {
  int _currentIndex = 0;
  PageController _pageController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: PageView(
          controller: _pageController,
          children: <Widget>[
            HomeContent(),
            CalendarContent(),
            AddContent(),
            ProjectsContent(),
            SettingsContent()
          ],
          onPageChanged: (index) {
            setState(() {
              _currentIndex = index;
            });
          },
        ),
      ),
      bottomNavigationBar: BottomNavyBar(
        selectedIndex: _currentIndex,
        showElevation: true,
        itemCornerRadius: 24,
        curve: Curves.elasticInOut,
        onItemSelected: (index) => setState(() {
          _currentIndex = index;
          _pageController.animateToPage(index,
              duration: Duration(milliseconds: 300), curve: Curves.ease);
        }),
        items: [
          BottomNavyBarItem(
            icon: Icon(Icons.home),
            title: Text('Home'),
            activeColor: Colors.deepPurple[800],
            inactiveColor: Colors.black45
          ),
          BottomNavyBarItem(
            icon: Icon(Icons.calendar_today_outlined),
            title: Text('Calendar'),
            activeColor: Colors.deepPurple[800],
            inactiveColor: Colors.black45
          ),
          BottomNavyBarItem(
            icon: Icon(Icons.add),
            title: Text('Add'),
            activeColor: Colors.deepPurple[800],
            inactiveColor: Colors.black45
          ),
          BottomNavyBarItem(
            icon: Icon(Icons.work_outline_outlined),
            title: Text('Projects'),
            activeColor: Colors.deepPurple[800],
            inactiveColor: Colors.black45
          ),
          BottomNavyBarItem(
            icon: Icon(Icons.settings),
            title: Text('Settings'),
            activeColor: Colors.deepPurple[800],
            inactiveColor: Colors.black45
          ),
        ],
      )
    );
  }
}

I tried with both page Controller Jump to page and the animateToPage but it either disables clicking on the items or it doesnt change page and just clicking behaviour works and not page changing one.

Also I tried with and without SizedBox.expand as parent of Page View but it didn't work.

I will try to make a new project and try it again to see if its this package problem or not.

Work with Routes

Hi,
this works fine with PageView on an app with a single StatefulWidget , but on a more complex app with multiple Stateful/Stateless classes connected using Navigator and each having a bottom navigation bar, the animation does not fire.

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

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

class _MyHomePageState extends State<MyHomePage> {
  int currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('MyPage'),
      ),
      body: Center(child: Text('MyPage')),
      bottomNavigationBar: BottomNavyBar(
        selectedIndex: currentIndex,
        showElevation: true,
        itemCornerRadius: 8,
        curve: Curves.easeInBack,
        onItemSelected: (index) => setState(() {
          Navigator.push(context,
              MaterialPageRoute(builder: (BuildContext context) => Page2()));
        }),
        items: [
          BottomNavyBarItem(
            icon: Icon(Icons.apps),
            title: Text('MyPage'),
            activeColor: Colors.red,
            textAlign: TextAlign.center,
          ),
          BottomNavyBarItem(
            icon: Icon(Icons.people),
            title: Text('Page2'),
            activeColor: Colors.purpleAccent,
            textAlign: TextAlign.center,
          ),
        ],
      ),
    );
  }
}

class Page2 extends StatefulWidget {
  @override
  _Page2State createState() => _Page2State();
}

class _Page2State extends State<Page2> {
  int currentIndex = 1;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavyBar(
        selectedIndex: currentIndex,
        showElevation: true,
        itemCornerRadius: 8,
        curve: Curves.easeInBack,
        onItemSelected: (index) => setState(() {
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (BuildContext context) => MyHomePage()));
        }),
        items: [
          BottomNavyBarItem(
            icon: Icon(Icons.apps),
            title: Text('MyPage'),
            activeColor: Colors.red,
            textAlign: TextAlign.center,
          ),
          BottomNavyBarItem(
            icon: Icon(Icons.people),
            title: Text('Page2'),
            activeColor: Colors.purpleAccent,
            textAlign: TextAlign.center,
          ),
        ],
      ),
      body: Center(
        child: Text('Page2'),
      ),
    );
  }
}

Too laggy

This is so Laggy!!!
Is there any way to solve this problem?

Disable Swiping Right or Left

Hello. Is it possible to disable Swiping Right or Left? I only want to switch between screens by clicking on the bottom navy bar icons, Not Swiping pages right or left

I really appreciate your work, Nice bottom_navy_bar 👍

Don't use specific widgets

BottomNavyBar forces us to pass an Icon and a Text. If those properties are of type Widget, then we can pass a lot more usefull things, like SVG icons with badges, etc.

I did this change and it should work without any breaking changes:

class BottomNavyBarItem {
  final Widge icon; // <--- Widget instead of Icon
  final Widget title; // <--- Widget instead of Text
  final Color activeColor;
  final Color inactiveColor;
  final TextAlign textAlign;

  BottomNavyBarItem({
    @required this.icon,
    @required this.title,
    this.activeColor = Colors.blue,
    this.textAlign,
    this.inactiveColor,
  }) {
    assert(icon != null);
    assert(title != null);
  }
}

BottomNavyBarItem is not selected

When the app is loaded, the navigation item is not selected by default, I have to manually tap to the current item to show overlay on the top of it.

Adding Tooltip to BottomNavyBar.items

Hello, I would like to add a Tooltip to every item in BottomNavyBar.items.

Currently, the items cannot easily be wrapped in a Tooltip since BottomNavyBar.items has the explicit type List<BottomNavyBarItem>.

Ideally, I think BottomNavyBar.items should be of type List<Widget> instead. Then, the BottomNavyBarItems can be wrapped with other Widgets without impacting the interface.

This works well in existing native Widgets, for example IconButton. IconButton.icon is typically an Icon, but the interface specifies Widget.

What are your thoughts on using the generic Widget type in this case?

Error when trying on PageView and PageController

I wrote the code same as tutorial, it ran normally, but I found an issue, when I trying to tap on item on the bottom navbar the page doesn't changed, but when I swipe left or right the page changed normally.

Please kindly check my codes below, thank you :)


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

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeState();
  }
}

class _HomeState extends State<Home> {
  int _currentIndex = 0;
  PageController _pageController;

  @override
  void initState() {
    super.initState();
    _pageController = PageController();
  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('MAL MALIOBORO'), centerTitle: true),
      body: SizedBox.expand(
        child: PageView(
          controller: _pageController,
          onPageChanged: (index) {
            setState(() => _currentIndex = index);
          },
          children: <Widget>[
            Container(
              color: Colors.blueGrey,
            ),
            Container(
              color: Colors.redAccent,
            ),
            Container(
              color: Colors.lightGreenAccent,
            ),
            Container(
              color: Colors.blueAccent,
            ),
          ],
        ),
      ),
      bottomNavigationBar: BottomNavyBar(
        selectedIndex: _currentIndex,
        showElevation: true,
        onItemSelected: (index) {
          setState(() => _currentIndex = index);
          _pageController.jumpToPage(index);
          _pageController.animateToPage(index,
              duration: Duration(microseconds: 300), curve: Curves.ease);
        },
        items: <BottomNavyBarItem>[
          BottomNavyBarItem(title: Text('Home'), icon: Icon(Icons.home)),
          BottomNavyBarItem(title: Text('Inbox'), icon: Icon(Icons.inbox)),
          BottomNavyBarItem(title: Text('Chat'), icon: Icon(Icons.chat_bubble)),
          BottomNavyBarItem(title: Text('Profile'), icon: Icon(Icons.person)),
        ],
      ),
    );
  }
}

Any chance to add badge inside the icon?

Hello,

Thanks for your awesome plugin.
I have a question: can we add the badge at the top of
In some cases, I want to show the number of message (for example)
Thanks

Bar is to low at iPhone X(s/R)

At the Bottom of the iPhone X... is the Navigation "Line". At this point there should be white space. The Navy Bar is behind this Line.

image

How it should look:

image

Scroll Position

The scroll position of one screen is getting reset after coming back from another.
ex: In HomePage i scrolled to bottom and went to another page then went to home page the scroll position is top. Any solution?

If i want to add newsfeed i need to maintain the scroll position it's necessary. Look into this.
Thanks.

Rounded corners

Hi,

Is there any option to add rounded top corners to the bar?

Thanks,
Pawel

Provide a background color when tab is activated

Hello,

I want to be able to apply my own backgroundColor on the container when tab is active. Can you expose a background color parameter and remove withOpacity(0.2) (or put opacity to 1) when backgroundColor is provided?

Is it possible to programmatically change the bottom nav position?

Hi, I really commend the great work put into this package.

Please I would like to know if it's possible to programmatically change the position of the tab.

For instance, I want to be able to transition the user to another page without them clicking on the bottom navigation bar.

Thanks.

Assert in Constructor

Thanks for posting your code. Nice stuff!

For line 24 in the constructor, there is the following assert:

assert(items.length >= 2 || items.length >= 5);

Shouldn't it be:

assert(items.length >= 2 && items.length <= 5);

As it stands, an items.length of 7 (for ex) would pass the test contrary to the requirements listed in your docs.

When the app is loaded the navigation item

I have the same issue and is inside of a Stetefull widget, I put the BottomNavyBar in the bottom part of the Appbar using PreferredSize, and when the app is loaded the navigation item is not selected by default.

bottom: PreferredSize(
            preferredSize: Size(0,40),
            child: BottomNavyBar(
              onItemSelected: (index) => setState(() {
                  _index = index;
                  _controllerTab.animateTo(_index);
              }),
              items: [
                BottomNavyBarItem(
                  icon: Icon(Icons.chrome_reader_mode),
                  title: Text('Referendum'),
                  activeColor: Colors.red,
                  inactiveColor: Colors.grey,
                ),
                BottomNavyBarItem(
                    icon: Icon(Icons.people),
                    title: Text('Pagar'),
                    activeColor: Colors.green,
                    inactiveColor: Colors.grey
                ),
                BottomNavyBarItem(
                    icon: Icon(Icons.message),
                    title: Text('Derechos'),
                    activeColor: Colors.deepPurple,
                    inactiveColor: Colors.grey,
                ),
                BottomNavyBarItem(
                    icon: Icon(Icons.settings),
                    title: Text('Notificaciones'),
                    activeColor: Colors.blue,
                    inactiveColor: Colors.grey,
                ),
              ],
            ),
          ),

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.