Fancybar In Flutter :
Fancybar In Flutter :today i will show you how to create beautiful fancybar in flutter.this is a fancy and animated widget for the flutter app
in this app we can add some costomization option like
items : items that appear in the bottom.it require more than one item and less than six item that means you can add maximum six item in the bar
in this flutter tutorial i am adding four item in the bottombar
selectIndex :it return the current item. index.use it to change the selected item. default value is zero
title : the title is display after the item is selected. you can see in this example when i press the home icon the title of home is displayed
Dependencies :
dependencies: fancy_bar: ^1.0.0
the final output for the fancybar in flutter and the code is given below.you can use following links to know more about flutter
BottomNavigationBar using TabBarView with UnderLine :
Screenshot :

fancy_bar.dart
library fancy_bar; import 'package:flutter/material.dart'; class FancyBottomBar extends StatefulWidget { final List<FancyItem> items; final selectedIndex; final ValueChanged<int> onItemSelected; FancyBottomBar({ this.items, this.selectedIndex, @required this.onItemSelected, }) { assert(items != null); assert(items.length >= 2 && items.length <= 4); assert(onItemSelected != null); } @override _FancyBottomBarState createState() => _FancyBottomBarState(); } class _FancyBottomBarState extends State<FancyBottomBar> { int pos = 0; void setItem(int _pos) { setState(() { pos = _pos; }); } @override Widget build(BuildContext context) { return Material( child: BottomAppBar( // shape: CircularNotchedRectangle(), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: widget.items.map((_item) { FancyItem item = _item; var index = widget.items.indexOf(_item); return InkWell( onTap: () { setItem(index); widget.onItemSelected(index); }, child: _ItemVWidget( item: item, isSelected: index == pos, length: widget.items.length, ), ); }).toList(), ), ), ); } } class _ItemVWidget extends StatelessWidget { final FancyItem item; final bool isSelected; final int length; const _ItemVWidget({Key key, this.item, this.isSelected, this.length}) : super(key: key); @override Widget build(BuildContext context) { return Container( width: MediaQuery.of(context).size.width / length, height: kBottomNavigationBarHeight, alignment: Alignment.center, child: AnimatedSwitcher( transitionBuilder: (Widget child, Animation<double> animation) { return ScaleTransition( scale: animation, child: child, ); }, duration: Duration(milliseconds: 250), child: isSelected ? Text( '${item.title}', style: TextStyle( color: item.textColor ?? Theme.of(context).primaryColor, fontWeight: FontWeight.bold, fontSize: 16), ) : item.icon, )); } } class FancyItem { Color textColor; String title; Widget icon; FancyItem({ @required this.textColor, @required this.title, @required this.icon, }); }
main.dart
import 'package:flutter/material.dart'; import 'fancy_bar.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { int _counter = 0; void _incrementCounter() { setState(() { _counter++; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( // Here we take the value from the MyHomePage object that was created by // the App.build method, and use it to set our appbar title. title: Text(widget.title), ), bottomNavigationBar: FancyBottomBar( items: [ FancyItem( textColor: Colors.orange, title: 'Home', icon: Icon(Icons.home), ), FancyItem( textColor: Colors.red, title: 'Trending', icon: Icon(Icons.trending_up), ), FancyItem( textColor: Colors.green, title: 'Search', icon: Icon(Icons.search), ), FancyItem( textColor: Colors.brown, title: 'Settings', icon: Icon(Icons.settings), ), ], onItemSelected: (index) { print(index); }, ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( 'You have pushed the button this many times:', ), Text( '$_counter', style: Theme.of(context).textTheme.display1, ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: _incrementCounter, tooltip: 'Increment', child: Icon(Icons.add), ), // This trailing comma makes auto-formatting nicer for build methods. ); } }
The flutter tutorial is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application
For more information about Flutter. visit www.fluttertutorial.in