Flutter Tutorial : Create Nav Bar with google_nav_bar Plugin

In this Tutorial, we will explain how to create a beautiful Nav Bar using Flutter with the google_nav_bar Plugin.

Flutter Tutorial : Create Nav Bar with google_nav_bar Plugin

1. google_nav_bar Plugin Installation

First, we will begin by installing the google_nav_bar plugin.
 
Add the package to the pubspec.yaml file
 
... 

dependencies: 

 google_nav_bar: ^5.0.6

Now, in your Dart code, you can use:

import 'package:google_nav_bar/google_nav_bar.dart'; 

2. Example of Usage

In this section, we will create an example of using this plugin.

Create a Stateful widget to contain your navigation bar

class GoogleNavBar extends StatefulWidget{
  @override
  State<GoogleNavBar> createState() => _GoogleNavBarState();
}

class _GoogleNavBarState extends State<GoogleNavBar> {
  int _selectedIndex = 0 ;

  _onTap(index){
    setState(() {
      _selectedIndex = index;
    });
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      bottomNavigationBar: Container(
        color: Colors.black,
        child:Padding(
          padding: EdgeInsets.symmetric(vertical: 15.0 , horizontal: 20.0),
          child:  GNav(
          gap: 8,
          tabBackgroundColor: Colors.grey.shade900,
          activeColor: Colors.white,
          color: Colors.grey,
          backgroundColor: Colors.black54,
          tabs: [
          GButton(icon: Icons.home  , text: "home") ,
          GButton(icon: Icons.favorite_border , text : "favorite" ) ,
          GButton(icon: Icons.search , text: "search"),
          GButton(icon: Icons.person , text:"profile")
          ],
          selectedIndex: _selectedIndex,
          onTabChange: _onTap

          ),
          ),
      ),
    );
  }

}

Then use GoogleNavBar in your application:

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: GoogleNavBar(),
    );
        }
}

Share Article:

Simple App :  a blog simplifying development and cybersecurity. Accessible guides and tips to boost your skills in tech and security

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • All Post
  • Article
  • Framework and library
  • Programming
  • Security
  • Web
    •   Back
    • JavaScript
    • CSS
    •   Back
    • Encryption
    •   Back
    • React
    • Flutter
    • NextJs
    •   Back
    • Java
    • Python

Join the family!

Sign up for a Newsletter.

You have been successfully Subscribed! Ops! Something went wrong, please try again.
Edit Template

About

Simple App :  a blog simplifying development and cybersecurity. Accessible guides and tips to boost your skills in tech and security

Recent Post

  • All Post
  • Article
  • Framework and library
  • Programming
  • Security
  • Web
    •   Back
    • JavaScript
    • CSS
    •   Back
    • Encryption
    •   Back
    • React
    • Flutter
    • NextJs
    •   Back
    • Java
    • Python

© 2024 Created by Simple App