Bottom Bar Animation In Flutter
Screenshot :

active_tab.dart
import 'package:flutter/material.dart'; class ActiveTab extends AnimatedWidget { final IconData iconData; final String text; ActiveTab({Key key, Animation animation, this.iconData, this.text}) : super(key: key, listenable: animation); @override Widget build(BuildContext context) { final Animation<double> animation = listenable; return Transform( transform: Matrix4.diagonal3Values(animation.value, 1, 1), child: Container( width: 100.0, height: 60.0, decoration: BoxDecoration( color: Colors.orange, borderRadius: BorderRadius.only( topLeft: Radius.circular(20.0), bottomLeft: Radius.circular(20.0), bottomRight: Radius.circular(20.0))), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[ Icon(iconData, color: Colors.white, size: 25), Text(text, style: TextStyle(color: Colors.white, fontSize: 14)) ]))); } }
bottom_bar.dart
import 'package:flutter/material.dart'; import 'active_tab.dart'; class BottomBar extends StatefulWidget { @override BottomBarState createState() => BottomBarState(); } class BottomBarState extends State<BottomBar> with SingleTickerProviderStateMixin { Animation animation; AnimationController animationController; int currentTab = 0; @override void initState() { super.initState(); animationController = AnimationController(vsync: this, duration: Duration(seconds: 1)); animation = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation(parent: animationController, curve: Curves.elasticOut)); animationController.forward(); } @override Widget build(BuildContext context) { return Container( height: 60, width: MediaQuery.of(context).size.width, padding: EdgeInsets.only(right: 16, bottom: 5, top: 10, left: 16), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[ _buildTab("Hotels", Icons.hotel, 0), _buildTab("Favorites", Icons.favorite, 1), _buildTab("Map", Icons.map, 2) ])); } Widget _buildTab(String text, IconData icon, int index) { return currentTab == index ? ActiveTab( animation: animation, key: Key(text), text: text, iconData: icon) : Material( child: InkWell( onTap: () { setState(() { currentTab = index; animationController.reset(); animationController.forward(); }); }, child: Icon(icon, size: 25))); } @override void dispose() { animationController.dispose(); super.dispose(); } }
home_page.dart
import 'package:flutter/material.dart'; import 'bottom_bar.dart'; class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return SafeArea( child: Scaffold(bottomNavigationBar: BottomBar(), body: Container())); } }
main.dart
import 'package:flutter/material.dart'; import 'package:hotelbooking/home_page.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Bottom Bar Animation', theme: ThemeData( primarySwatch: Colors.blue, primaryColor: Colors.blueAccent, accentColor: Colors.blue, fontFamily: 'avenir', cardColor: Colors.white), home: HomePage()); } }
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