skip to Main Content

This is my home screen.

import ‘package:flutter/material.dart’;

import ‘package:quotationbox/screens/Drawer/drawer.dart’;

import ‘../Dashboard/CategoryFragment.dart’;

import ‘../Dashboard/FilterFragment.dart’;

import ‘../Dashboard/HomeFragment.dart’;

import ‘../Dashboard/NotificationFragment.dart’;

import ‘../Dashboard/ProfileFragment.dart’;

class HomeScreen extends StatefulWidget {

@override

_HomeScreenState createState() => _HomeScreenState();

}

class _HomeScreenState extends State with TickerProviderStateMixin {

int _currentIndex = 0;

@override

void initState() {

super.initState();

}

void navigationTapped(int page) {

setState(() {

  _currentIndex = page;

});

}

@override

Widget build(BuildContext context) {

List<Widget> _allPages = [

  HomeFragment(),

  CategoryFragment(),

  NotificationFragment(),

  FilterFragment(),

  ProfileFragment(),

];

return Scaffold(

  drawer: MyDrawer(),

  body: _allPages[_currentIndex],

  bottomNavigationBar: buildBottomNavigationBar(),

);

}

BottomNavigationBar buildBottomNavigationBar() {

return BottomNavigationBar(

  type: BottomNavigationBarType.fixed,

  fixedColor: Colors.red,

  currentIndex: _currentIndex,

  onTap: navigationTapped,

  items: [

    BottomNavigationBarItem(

      icon: ImageIcon(

        AssetImage("images/app_images/home.png"),

      ),

      label: "Home",

    ),

    BottomNavigationBarItem(

      icon: ImageIcon(

        AssetImage("images/app_images/category.png"),

      ),

      label: "Category",

    ),

    BottomNavigationBarItem(

        icon: ImageIcon(

          AssetImage("images/app_images/notification.png"),

        ),

      label: "Notification"

    ),

    BottomNavigationBarItem(

        icon: ImageIcon(

          AssetImage("images/app_images/calendar.png"),

        ),

     label: "Filter"

    ),

    BottomNavigationBarItem(

        icon: ImageIcon(

          AssetImage("images/app_images/profile.png"),

        ),

     label: "Profile"

    ),

  ],

);

}

//This is my home fragment

import ‘package:carousel_slider/carousel_slider.dart’;

import ‘package:quotationbox/screens/Dashboard/ProfileFragment.dart’;

import ‘package:quotationbox/screens/Merchant/merchant_list.dart’;

import ‘../../colors_constant.dart’;

import ‘../../utils/common_background.dart’;

import ‘../Drawer/drawer.dart’;

import ‘dart:math’;

import ‘package:flutter/material.dart’;

import ‘package:dots_indicator/dots_indicator.dart’;

import ‘package:smooth_page_indicator/smooth_page_indicator.dart’;

import ‘../Offer/myofferscreen.dart’;

import ‘../Quotation/Job/postjob.dart’;

class HomeFragment extends StatefulWidget {

const HomeFragment({super.key});

@override

State createState() => _HomeFragmentState();

}

class _HomeFragmentState extends State {

GlobalKey _scaffoldState = GlobalKey();

final items = [

Image.asset('images/app_images/ads.png',fit: BoxFit.cover,height: 180,),

Image.asset('images/app_images/ads.png',fit: BoxFit.cover,height: 180,),

Image.asset('images/app_images/ads.png',fit: BoxFit.cover,height: 180,)

];

int currentIndex = 0;

final _scaffoldKey = GlobalKey();

final controller = PageController(viewportFraction: 0.8, keepPage: true);

@override

Widget build(BuildContext context) {

return Scaffold(

  backgroundColor: AppColors.darkgreen,

  key: _scaffoldKey,

  drawer: MyDrawer(),

  body:

  CustomScrollView(

    slivers: [

      SliverFillRemaining(

        hasScrollBody: false,

        child: Column(

          crossAxisAlignment: CrossAxisAlignment.start,

          children: <Widget>[

            Container(

              padding: EdgeInsets.only(

                  top: 60.0, left: 15.0, right: 10, bottom: 30.0),

              child: Column(

                crossAxisAlignment: CrossAxisAlignment.start,

                children: <Widget>[

                  Row(

                    // mainAxisAlignment: MainAxisAlignment.spaceEvenly,

                    children: [

                      Align(

                          alignment: Alignment.centerLeft,

                          child: GestureDetector(

                            onTap: () => _scaffoldKey.currentState!.openDrawer(),

                            child: Container(

                              height: 20,

                              width: 25,

                              decoration: const BoxDecoration(

                                image: DecorationImage(

                                  image: AssetImage('images/app_images/ic_menu.png'),

                                  fit: BoxFit.cover,

                                ),

                              ),

                            ),

                          )

                      ),

                      Expanded(

                        child: Align(

                          alignment: Alignment.center,

                          child: Container(

                            child: ElevatedButton(

                              style: ElevatedButton.styleFrom(

                                // backgroundColor: AppColors.yellowColorContainer,

                                backgroundColor: AppColors.yellowColorContainer,

                                side: const BorderSide(

                                    width: 3, color: AppColors.yellowColorContainer),

                              ),

                              onPressed: () {

                                Navigator.of(context).push(new MaterialPageRoute(

                                    builder: (context) => PostJob()));

                              }, child: Text("Request Quotation",style: TextStyle(color: Colors.black,fontSize: 15),),

                            ),

                          ),

                        ),

                      ),

                      //Expanded(

                      //  child:

                      Align(

                        alignment: Alignment.centerRight,

                        child: GestureDetector(

                          onTap: (){

                            Navigator.of(context).push(new MaterialPageRoute(

                                builder: (context) => ProfileFragment()));

                          },

                          child: Container(

                            //color: Colors.white,

                            child: Padding(

                                padding: EdgeInsets.only(right: 10),

                                child: CircleAvatar(

                                  radius: 20.0,

                                  backgroundImage:

                                  NetworkImage('https://via.placeholder.com/150'),

                                  backgroundColor: Colors.transparent,

                                )

                            ),

                          ),

                        ),

                      ),

                      // ),

                    ],

                  ),

                ],

              ),

            ),

            Expanded(

              child: Container(

                width: MediaQuery.of(context).size.width,

                padding: EdgeInsets.symmetric(horizontal: 20.0),

                decoration: BoxDecoration(

                  color: Colors.white,

                  borderRadius: BorderRadius.only(

                    topLeft: Radius.circular(20.0),

                    topRight: Radius.circular(20.0),

                  ),

                ),

                child: SingleChildScrollView(

                  child: Container(

                    decoration: baseBackgroundDecoration,

                    child: Column(

                      children: [

                        Padding(

                          padding: EdgeInsets.only(left: 0,right: 0,top: 20,bottom: 10),

                          child: Container(

                            height: 180,

                            // decoration: BoxDecoration(

                            //     border: Border.all(

                            //       color: Colors.grey.shade400,

                            //     ),

                            //     borderRadius: BorderRadius.all(Radius.circular(20))

                            // ),

                            child: CarouselSlider(

                              options: CarouselOptions(

                                autoPlay: true,

                                aspectRatio: 2.0,

                                enlargeCenterPage: true,

                                onPageChanged: (index, reason) {

                                  setState(() {

                                    currentIndex = index;

                                  });

                                },

                              ),

                              items: items,

                            ),

                          ),

                        ),

                        // DotsIndicator(

                        //   dotsCount: items.length,

                        //   position: currentIndex,

                        // ),

                        Container(

                          child: SmoothPageIndicator(

                            controller: controller,  // PageController

                            count: items.length,

                            effect:  ExpandingDotsEffect(

                              dotColor: Colors.grey,

                              dotHeight: 7,

                              activeDotColor: Colors.yellow,

                            ),

                            // dotHeight: 16,

                            // dotWidth: 16,

                            // jumpScale: .7,

                            // verticalOffset: 15,// your preferred effect

                          ),

                        ),

                        SizedBox(

                          height: 30,

                        ),

                        Row(

                          mainAxisAlignment: MainAxisAlignment.spaceBetween,

                          children: [

                            Padding(

                                padding: EdgeInsets.only(left: 0),

                                child: Text("Latest Merchant",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 20),)),

                            Padding(

                                padding: EdgeInsets.only(right: 0),

                                child: GestureDetector(

                                    onTap: (){

                                      Navigator.of(context).push(new MaterialPageRoute(

                                          builder: (context) => MerchantListScreen()));

                                    },

                                    child: Container(child: Text("See all",style: TextStyle(fontWeight: FontWeight.normal,fontSize: 15,color: Colors.redAccent),))))

                          ],

                        ),

                        merchantList(),

                        SizedBox(

                          height: 20,

                        ),

                        Row(

                          mainAxisAlignment: MainAxisAlignment.spaceBetween,

                          children: [

                            Padding(

                                padding: EdgeInsets.only(left: 0),

                                child: Text("Premium Client",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 20),)),

                            Padding(

                                padding: EdgeInsets.only(right: 0),

                                child: Text("See all",style: TextStyle(fontWeight: FontWeight.normal,fontSize: 15,color: Colors.redAccent),))

                          ],

                        ),

                        clientList(),

                      ],

                    ),

                  ),

                ),

              ),

            ),

          ],

        ),

      ),

    ],

  )

);

}

Widget merchantList(){

return Container(

    height: 180.0,

    child: ListView.builder(

      scrollDirection: Axis.horizontal,

      itemCount: 3,

      itemBuilder: (BuildContext context, int i) =>

          Padding(

            padding: EdgeInsets.only(left: 5,right: 5),

            child: Card(

              child: Container(

                width: 150.0,

                child: Column(

                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,

                  children: <Widget>[

                    Container(

                      child: Image.asset("images/app_images/electric.png",fit: BoxFit.cover,),

                    ),

                    Container(

                      child: Text("Electric"),

                    )

                  ],

                ),

              ),

            ),

          ),

    )

);

}

Widget clientList(){

return Padding(

  padding: EdgeInsets.only(left: 5,right: 5),

  child: Container(

      height: 180.0,

      child: ListView.builder(

        scrollDirection: Axis.horizontal,

        itemCount: 3,

        itemBuilder: (BuildContext context, int i) =>

            Card(

              child: Container(

                width: 150.0,

                child: Column(

                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,

                  children: <Widget>[

                    Container(

                      child: Image.asset("images/app_images/adidas.png",fit: BoxFit.cover,),

                    ),

                    Container(

                      child: Text("Adidas"),

                    )

                  ],

                ),

              ),

            ),

      )

  ),

);

}

}

I don’t know why Bottom navigation bar is not working in my app.

2

Answers


  1. it works here

    home_screen.dart

    class HomeScreen extends StatefulWidget {
      const HomeScreen({super.key});
    
      @override
      _HomeScreenState createState() => _HomeScreenState();
    }
    
    class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
      int _currentIndex = 0;
    
      @override
      void initState() {
        super.initState();
      }
    
      void navigationTapped(int page) {
        setState(() {
          _currentIndex = page;
        });
      }
    
      @override
      Widget build(BuildContext context) {
        List<Widget> _allPages = [
          const HomeFragment(),
          Container(
            color: Colors.red,
          ),
          Container(
            color: Colors.black,
          ),
          Container(
            color: Colors.pink,
          ),
          Container(
            color: Colors.white,
          ),
        ];
    
        return Scaffold(
          drawer: const Drawer(),
          body: _allPages[_currentIndex],
          bottomNavigationBar: buildBottomNavigationBar(),
        );
      }
    
      BottomNavigationBar buildBottomNavigationBar() {
        return BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          fixedColor: Colors.red,
          currentIndex: _currentIndex,
          onTap: navigationTapped,
          items: const [
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: "Home",
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.category),
              label: "Category",
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.notifications_active_sharp),
                label: "Notification"),
            BottomNavigationBarItem(
                icon: Icon(Icons.filter_alt_sharp), label: "Filter"),
            BottomNavigationBarItem(icon: Icon(Icons.person), label: "Profile"),
          ],
        );
      }
    }
    

    home_fragment.dart

    import 'package:carousel_slider/carousel_slider.dart';
    import 'package:flutter/material.dart';
    import 'package:smooth_page_indicator/smooth_page_indicator.dart';
    
    class HomeFragment extends StatefulWidget {
      const HomeFragment({super.key});
    
      @override
      State<HomeFragment> createState() => _HomeFragmentState();
    }
    
    class _HomeFragmentState extends State<HomeFragment> {
      GlobalKey<ScaffoldState> _scaffoldState = GlobalKey<ScaffoldState>();
    
      final items = [
        Image.asset(
          'images/app_images/ads.png',
          fit: BoxFit.cover,
          height: 180,
        ),
        Image.asset(
          'images/app_images/ads.png',
          fit: BoxFit.cover,
          height: 180,
        ),
        Image.asset(
          'images/app_images/ads.png',
          fit: BoxFit.cover,
          height: 180,
        )
      ];
    
      int currentIndex = 0;
    
      final _scaffoldKey = GlobalKey<ScaffoldState>();
    
      final controller = PageController(viewportFraction: 0.8, keepPage: true);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            backgroundColor: Colors.green,
            key: _scaffoldKey,
            drawer: const Drawer(),
            body: CustomScrollView(
              slivers: [
                SliverFillRemaining(
                  hasScrollBody: false,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Container(
                        padding: const EdgeInsets.only(
                            top: 60.0, left: 15.0, right: 10, bottom: 30.0),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Row(
                              // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
    
                              children: [
                                Align(
                                    alignment: Alignment.centerLeft,
                                    child: GestureDetector(
                                      onTap: () =>
                                          _scaffoldKey.currentState!.openDrawer(),
                                      child: Container(
                                        height: 20,
                                        width: 25,
                                        decoration: const BoxDecoration(
                                          image: DecorationImage(
                                            image: AssetImage(
                                                'images/app_images/ic_menu.png'),
                                            fit: BoxFit.cover,
                                          ),
                                        ),
                                      ),
                                    )),
    
                                Expanded(
                                  child: Align(
                                    alignment: Alignment.center,
                                    child: Container(
                                      child: ElevatedButton(
                                        style: ElevatedButton.styleFrom(
                                          // backgroundColor: AppColors.yellowColorContainer,
    
                                          backgroundColor: Colors.yellowAccent,
    
                                          side: const BorderSide(
                                              width: 3, color: Colors.yellowAccent),
                                        ),
                                        onPressed: () {},
                                        child: const Text(
                                          "Request Quotation",
                                          style: TextStyle(
                                              color: Colors.black, fontSize: 15),
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
    
                                //Expanded(
    
                                //  child:
    
                                Align(
                                  alignment: Alignment.centerRight,
                                  child: GestureDetector(
                                    onTap: () {},
                                    child: const Padding(
                                        padding: EdgeInsets.only(right: 10),
                                        child: CircleAvatar(
                                          radius: 20.0,
                                          backgroundImage: NetworkImage(
                                              'https://via.placeholder.com/150'),
                                          backgroundColor: Colors.transparent,
                                        )),
                                  ),
                                ),
    
                                // ),
                              ],
                            ),
                          ],
                        ),
                      ),
                      Expanded(
                        child: Container(
                          width: MediaQuery.of(context).size.width,
                          padding: const EdgeInsets.symmetric(horizontal: 20.0),
                          decoration: const BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.only(
                              topLeft: Radius.circular(20.0),
                              topRight: Radius.circular(20.0),
                            ),
                          ),
                          child: SingleChildScrollView(
                            child: Container(
                              // decoration: baseBackgroundDecoration,
                              child: Column(
                                children: [
                                  Padding(
                                    padding: const EdgeInsets.only(
                                        left: 0, right: 0, top: 20, bottom: 10),
                                    child: SizedBox(
                                      height: 180,
                                      child: CarouselSlider(
                                        options: CarouselOptions(
                                          autoPlay: true,
                                          aspectRatio: 2.0,
                                          enlargeCenterPage: true,
                                          onPageChanged: (index, reason) {
                                            setState(() {
                                              currentIndex = index;
                                            });
                                          },
                                        ),
                                        items: items,
                                      ),
                                    ),
                                  ),
                                  Container(
                                    child: SmoothPageIndicator(
                                      controller: controller, // PageController
    
                                      count: items.length,
    
                                      effect: const ExpandingDotsEffect(
                                        dotColor: Colors.grey,
                                        dotHeight: 7,
                                        activeDotColor: Colors.yellow,
                                      ),
    
                                      // dotHeight: 16,
    
                                      // dotWidth: 16,
    
                                      // jumpScale: .7,
    
                                      // verticalOffset: 15,// your preferred effect
                                    ),
                                  ),
                                  const SizedBox(
                                    height: 30,
                                  ),
                                  Row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    children: [
                                      const Padding(
                                          padding: EdgeInsets.only(left: 0),
                                          child: Text(
                                            "Latest Merchant",
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                fontSize: 20),
                                          )),
                                      Padding(
                                          padding: const EdgeInsets.only(right: 0),
                                          child: GestureDetector(
                                              onTap: () {},
                                              child: Container(
                                                  child: const Text(
                                                "See all",
                                                style: TextStyle(
                                                    fontWeight: FontWeight.normal,
                                                    fontSize: 15,
                                                    color: Colors.redAccent),
                                              ))))
                                    ],
                                  ),
                                  merchantList(),
                                  const SizedBox(
                                    height: 20,
                                  ),
                                  const Row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    children: [
                                      Padding(
                                          padding: EdgeInsets.only(left: 0),
                                          child: Text(
                                            "Premium Client",
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                fontSize: 20),
                                          )),
                                      Padding(
                                          padding: EdgeInsets.only(right: 0),
                                          child: Text(
                                            "See all",
                                            style: TextStyle(
                                                fontWeight: FontWeight.normal,
                                                fontSize: 15,
                                                color: Colors.redAccent),
                                          ))
                                    ],
                                  ),
                                  clientList(),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ));
      }
    
      Widget merchantList() {
        return SizedBox(
            height: 180.0,
            child: ListView.builder(
              scrollDirection: Axis.horizontal,
              itemCount: 3,
              itemBuilder: (BuildContext context, int i) => Padding(
                padding: const EdgeInsets.only(left: 5, right: 5),
                child: Card(
                  child: SizedBox(
                    width: 150.0,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        Container(
                          child: Image.asset(
                            "images/app_images/electric.png",
                            fit: BoxFit.cover,
                          ),
                        ),
                        Container(
                          child: const Text("Electric"),
                        )
                      ],
                    ),
                  ),
                ),
              ),
            ));
      }
    
      Widget clientList() {
        return Padding(
          padding: const EdgeInsets.only(left: 5, right: 5),
          child: SizedBox(
              height: 180.0,
              child: ListView.builder(
                scrollDirection: Axis.horizontal,
                itemCount: 3,
                itemBuilder: (BuildContext context, int i) => Card(
                  child: SizedBox(
                    width: 150.0,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        Container(
                          child: Image.asset(
                            "images/app_images/adidas.png",
                            fit: BoxFit.cover,
                          ),
                        ),
                        Container(
                          child: const Text("Adidas"),
                        )
                      ],
                    ),
                  ),
                ),
              )),
        );
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search