qqmikey / kf_drawer

Flutter drawer (dynamic ready side menu)
MIT License
213 stars 52 forks source link

KF_drawer With Bottom Navigation Bar #10

Closed abhishekdana1999 closed 3 years ago

abhishekdana1999 commented 4 years ago

Hello Developer Actually I was making app which contains both drawer and bottom navigation but I am not able to do that please add function to add both together.

Some Code Demo

import 'package:drawer/pages/mainpage.dart';
import 'package:drawer/shared/drawer.dart';

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(

        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Plaza'),
    );
  }
}

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 _currentIndex = 0;

 static  List _widgetOptions = [
    MainPage(), 
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        backgroundColor: Colors.transparent,
        title: Text(widget.title , style: TextStyle(color: Colors.black54,fontSize: 26 , fontWeight: FontWeight.w600),),
      ),
      **body: Center(
        child: _widgetOptions.elementAt(_currentIndex),
      ),** // Here i can only add one thing that is a drawer or bottom navigation bar
      bottomNavigationBar: BottomNavigationBar(
        elevation: 2,
        onTap: onTabTapped,
        currentIndex: _currentIndex,
        items: [
          BottomNavigationBarItem(
            icon: Icon(
              Icons.fastfood,
              color: Colors.black,
            ),
            title: Text(
              'Recipies',
              style: TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.black,
              ),
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.local_offer,
              color: Colors.black,
            ),
            title: Text(
              'Brands',
              style: TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.black,
              ),
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.restaurant_menu,
              color: Colors.black,
            ),
            title: Text(
              'Menu',
              style: TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.black,
              ),
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.person,
              color: Colors.black,
            ),
            title: Text(
              'Profile',
              style: TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.black,
              ),
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.shopping_basket,
              color: Colors.black,
            ),
            title: Text(
              'Cart',
              style: TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.black,
              ),
            ),
          ),
        ],
      ),
    );
  }

   void onTabTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }
}