How To Add Background Gradient In Bottom Navigation bar Flutter

admin_img Posted By Bajarangi soft , Posted On 23-09-2020

I want to make the background of the Bottom Navigation bar a gradient, How can i do it.

Background gradient with bottom navigationbar in flutter

Bottom Navigation bar  does not have that feature by default. But you can make an Bottom Navigation bar  like widget which will have a gradient background as follow:
Step-1:
You can install gradient_Bottom_Navigation_bar

 

dependencies:
  flutter:
    sdk: flutter
  gradient_bottom_navigation_bar: ^1.0.0+4

Step-2:
You can install packages from the command line: with Flutter:

flutter pub get


step-3:
Now in your Dart code, you can use:
import 'package:gradient_bottom_navigation_bar/gradient_bottom_navigation_bar.dart';

You can add this gradient_Bottom_Navigation_bar code :
 
bottomNavigationBar: GradientBottomNavigationBar(
  backgroundColorStart: Colors.red,
  backgroundColorEnd: Colors.purple,
  items: <BottomNavigationBarItem>[
    BottomNavigationBarItem(icon: Icon(Icons.message), title: Text('Message')),
    BottomNavigationBarItem(icon: Icon(Icons.settings), title: Text('Setting')),
    BottomNavigationBarItem(icon: Icon(Icons.mail_outline), title: Text('Mail')),
  ],
  onTap: (index) {
    //Handle button tap
  },
),

Complete Code  gradient_Bottom_Navigation_bar  in flutter
Main.dart
import 'package:flutter/material.dart';
import 'package:gradient_bottom_navigation_bar/gradient_bottom_navigation_bar.dart';


void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'App Design',
      home: MyHomePage(),
    );
  }
}

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(
        centerTitle: true,
        title: Text(' Gradiant Background'),
        backgroundColor: Colors.purple,
      ),
      body: Center(
        child: Text('Welcome BajarangiSoft'),
      ),
      bottomNavigationBar: GradientBottomNavigationBar(
        backgroundColorStart: Colors.red,
        backgroundColorEnd: Colors.purple,
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.message), title: Text('Message')),
          BottomNavigationBarItem(icon: Icon(Icons.settings), title: Text('Setting')),
          BottomNavigationBarItem(icon: Icon(Icons.mail_outline), title: Text('Mail')),
        ],
        onTap: (index) {
          //Handle button tap
        },
      ),
    );
  }
}

Related Post