Facebook Twitter Instagram
    DeepCrazyWorld
    Facebook Twitter Instagram Pinterest YouTube
    • FLUTTER
      • FLUTTER APP
        • QRCode
        • Quiz App
        • Chat GPT
        • PDF App
        • News App
        • Fitness App
        • Weather App
        • BMI Calculator
        • GAME APP
        • Ecommerce App
        • wallpaper App
        • Finance app
        • Chat App
        • Wallet App
        • Taxi App
        • Quran app
        • Music player app
      • FLUTTER UI
        • Splash Screen
        • Onboarding Screen
        • Login Screen
        • Card Design
        • Drawer
    • PROJECT
      • Android Projects
      • College Projects
      • FLUTTER APP
      • Project Ideas
      • PHP Projects
      • Python Projects
    • SOURCE CODE
    • ANDROID
      • ANDROID APP
      • GAME APP
      • ANDROID STUDIO
    • MCQ
      • AKTU MCQ
        • RPA MCQ
        • COA MCQ
        • HPC MCQ
        • SPM MCQ
        • Renewable Energy All MCQ
        • Data Compression MCQ
        • Data Structure MCQ
        • Digital Image Processing MCQ
        • Software Engineering MCQ
        • Machine Learning MCQ
        • Artificial Intelligence MCQ
      • D PHARMA MCQ
        • Pharmaceutics – I MCQ
        • Pharmacognosy MCQ
        • Pharmaceutical Chemistry MCQ
        • Biochemistry and Clinical Pathology MCQ
        • Human Anatomy and Physiology MCQ
        • Heath Education and Community Pharmacy MCQ
    • INTERVIEW QUESTIONS
      • Flutter Interview Questions
      • INTERVIEW QUESTIONS
      • Python Interview Questions
      • Coding ninjas solution
    • MORE
      • WORDPRESS
        • SEO
        • TOP 10 WORDPRESS THEME
      • PRODUCTIVITY
      • Program
      • QUOTES
    DeepCrazyWorld
    Home»BottomNavigationBar»How to make custom BottomNavigationBar in flutter with source code
    BottomNavigationBar

    How to make custom BottomNavigationBar in flutter with source code

    DeepikaBy DeepikaAugust 19, 2024Updated:August 19, 2024No Comments4 Mins Read

    To create a bottom sheet with the given BottomNavigationBar code in a Flutter application, you can follow these steps:

    1. Create a new Flutter project (if you haven’t already).
    2. Set up the basic structure of your Flutter app, including a Scaffold with a BottomNavigationBar.
    3. Implement the bottom sheet functionality which will be triggered when an item in the BottomNavigationBar is tapped.

    Here is a step-by-step guide:

    Table of Contents

    Toggle
    • Step 1: Set Up Your Flutter Project
    • Step 2: Modify the Main File
    • Step 3: Run Your App
    • Explanation:
    • Output
    • Related Articles

    Step 1: Set Up Your Flutter Project

    If you haven’t already set up a Flutter project, you can create one using the following command in your terminal:

    flutter create bottom_sheet_example

    Navigate into your project directory:

    cd bottom_sheet_example

    Step 2: Modify the Main File

    Open the lib/main.dart file and replace its contents with the following code:

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Bottom Sheet Example',
          theme: ThemeData(
            primarySwatch: Colors.green,
          ),
          home: MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      int _selectedIndex = 0;
    
      static const List<Widget> _widgetOptions = <Widget>[
        Text('My Dairy Page'),
        Text('Support Group Page'),
        Text('Talk Now Page'),
        Text('Buddy Connect Page'),
        Text('Appointment Page'),
      ];
    
      void _onItemTapped(int index) {
        setState(() {
          _selectedIndex = index;
        });
        _showBottomSheet(context, index);
      }
    
      void _showBottomSheet(BuildContext context, int index) {
        showModalBottomSheet(
          context: context,
          builder: (context) {
            return Container(
              height: 200,
              child: Center(
                child: _widgetOptions.elementAt(index),
              ),
            );
          },
        );
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Bottom Sheet Example'),
          ),
          body: Center(
            child: _widgetOptions.elementAt(_selectedIndex),
          ),
          bottomNavigationBar: BottomNavigationBar(
            items: const <BottomNavigationBarItem>[
              BottomNavigationBarItem(
                icon: Icon(Icons.book),
                label: 'My Dairy',
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.groups),
                label: 'Support Group',
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.chat),
                label: 'Talk Now',
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.chat_bubble_outline),
                label: 'Buddy Connect',
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.calendar_today),
                label: 'Appointment',
              ),
            ],
            currentIndex: _selectedIndex,
            selectedItemColor: Colors.green,
            unselectedItemColor: Colors.black.withOpacity(0.8),
            selectedLabelStyle: TextStyle(
              color: Colors.green,
              fontSize: 10,
            ),
            unselectedLabelStyle: TextStyle(
              fontSize: 10,
              color: Colors.black.withOpacity(0.8),
            ),
            selectedIconTheme: const IconThemeData(
              size: 20,
            ),
            unselectedIconTheme: const IconThemeData(
              size: 20,
            ),
            onTap: _onItemTapped,
            type: BottomNavigationBarType.fixed,
          ),
        );
      }
    }

    Step 3: Run Your App

    Now, run your app using the following command:

    flutter run

    Explanation:

    1. Main File Setup: The MyApp class sets up the MaterialApp with a basic theme and the home page as MyHomePage.
    2. State Management: The _MyHomePageState class manages the selected index of the BottomNavigationBar and defines the options for each tab.
    3. BottomNavigationBar: The BottomNavigationBar is configured with five items. The _onItemTapped method updates the selected index and shows the bottom sheet.
    4. Bottom Sheet: The _showBottomSheet method uses showModalBottomSheet to display a bottom sheet with the content corresponding to the selected tab.

    This setup provides a basic implementation of a BottomNavigationBar that shows a bottom sheet when an item is tapped. You can customize the content of the bottom sheet and the appearance of the BottomNavigationBar items as needed.

    Output

    Here’s the correct UI for the code in image form BottomNavigationBar code in a Flutter:

    This image accurately represents the BottomNavigationBar and the bottom sheet functionality as described in the code.

    <img decoding=

    Related Articles

    • How to make Ludo app in Flutter with Source Code Step by step
    • How to make PDF Reader app in Flutter with Source Code Step by step
    • How to make QR Scanner app in Flutter with Source Code Step by step
    • How to Make a ToDo App with Flutter with source Code StepWise in 2024
    • What is package in Flutter (Dart) with example in 2024
    • What is class in Flutter(Dart) with example step by step
    • Advantage of Flutter with examples in 2024
    • Top 15 Amazing Applications Built with Flutter Framework
    • Specialized PDF reader designed specifically for music sheets
    • Flutter File Integrity Checker app for checking integrity of a file
    • Christmas Quote Generator app built with flutter source code
    • Create fast food orders and bundle it up into a QR code with flutter

    Share. Facebook Twitter LinkedIn WhatsApp Telegram Pinterest Reddit Email
    Previous ArticleCreating a Ludo app in Flutter with Source Code Step by step
    Next Article How to Make Image to Pdf Converter app in Flutter with Source Code

    Related Posts

    Implementing a Dynamic FAQ Screen UI in Flutter Using ExpansionTile

    FLUTTER 5 Mins Read

    Animated Backgrounds in Flutter: A Complete Guide

    FLUTTER 4 Mins Read

    How to make Diary App using flutter stepwise using getx

    FLUTTER APP 4 Mins Read

    How to Create Music Player UI screen with fully functional in flutter

    FLUTTER APP 3 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • Implementing a Dynamic FAQ Screen UI in Flutter Using ExpansionTile March 29, 2025
    • Creating an Instruction UI Screen in Flutter Application March 29, 2025
    • Animated Backgrounds in Flutter: A Complete Guide March 15, 2025
    • How to make Diary App using flutter stepwise using getx August 31, 2024
    • How to Create Music Player UI screen with fully functional in flutter August 30, 2024
    • How to make ListView Builder Ui in flutter with Source Code August 29, 2024
    • Create a TabBar View in flutter with fully functional stepwise August 28, 2024
    • How to create TabBar view in flutter with source code step wise August 27, 2024
    • How to make Heart rate measure app with Flutter stepwise August 26, 2024
    • How to make ChatGpt App in flutter with source code Stepwise August 25, 2024
    Facebook Twitter Instagram Pinterest YouTube
    • About
    • Contact
    • Disclaimer
    • Privacy Policy
    Copyright by DeepCrazyWorld © 2025

    Type above and press Enter to search. Press Esc to cancel.