GithubHelp home page GithubHelp logo

weblineindia / flutter-drawer Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 1.0 709 KB

A Flutter based Reusable Drawer component which provides Drawer menu with configurable items and dynamic views that can be used in any Flutter application.

Home Page: https://www.weblineindia.com/software-development-resources.html

License: MIT License

Kotlin 3.45% Swift 3.34% Objective-C 0.31% Dart 92.90%
flutter flutter-demo flutter-components flutter-examples flutter-plugin reusable-components flutter-library flutter-drawer drawer-menu drawer-component

flutter-drawer's Introduction

Flutter - Drawer Component

A Flutter based Reusable Drawer component which provides Drawer menu with configurable items and dynamic views that can be used in any Flutter application.

Table of contents

Flutter Support

Version - Flutter 1.17 (stable)

We have tested our program in above version, however you can use it in other versions as well.

Demo


Features

  • Drawer with Customizable Menu header.
  • Drawer with Customizable Menu icons.
  • Customizable UI with trailing items.

Getting started

  • Download this sample project and import app_drawer.dart Widget file in your Flutter App.
  • Update Header, Title based on your requirements.

Usage

Setup process is described below to integrate in project.

Configure DrawerMenu in your widget by following below method steps

Methods

Step 1.Add 'provider' package to pubspec.yaml

Step 2. Add MultiProvider in Your application widget like this

// Put DrawerNavigationProvider as mention below
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final MaterialColor colorCustom = MaterialColor(0xFFFACA58, color);
    return MultiProvider(
      providers: [
        ChangeNotifierProvider.value(
          value: DrawerNavigationProvider(),
        )
      ],
      child: MaterialApp(
        title: 'Flutter Demo',
        home: ...,
      ),
    );
  }
}

Step 3. User following DrawerVC constructor for adding drawer to user main screen

   Color selectedTextColor;
   Color textColor;
   int selectedIndex;
   bool isHeader = true;
   bool isShowIcon = true;
   Widget headerWidget;
   List<DrawerMenuItem> arrDrawerItems;
   Function(int) didItemSelected;
   
   DrawerVC({
        this.arrDrawerItems,
        this.isHeader,
        this.headerWidget,
        this.isShowIcon,
        this.textColor,
        this.selectedTextColor,
        this.didItemSelected,
    });
    
    // Pass DrawerMenuItem Array to the DrawerVC's Constructor
    class DrawerMenuItem {
      String title;
      IconData icon;
      Widget subItemWidget;

      // ignore: sort_constructors_first
      DrawerMenuItem({this.title, this.icon, this.subItemWidget});
    }

Step 4. Pass header widget if you want to add it otherwise skip it

this.isHeader = true // if you want to add header make sure you need to set this flag to true
headerWidget: Widget() 

Step 5.if you want set text color and selected text color

textColor: Colors.white
selectedTextColor: Colors.white

Step 6.if you want enable/disable Drawer item icons

isShowIcon : true // if you want to show icon the set this to true otherwise false

Step 7.if you want add trailing item icons then pass widget to DrawerMenuItem class using below constructor

  subItemWidget : Widget() // use this parameter to set trailing icons to drawer
   
// Pass DrawerMenuItem Array to the DrawerVC's Constructor
       class DrawerMenuItem {
         String title;
         IconData icon;
         Widget subItemWidget;

         // ignore: sort_constructors_first
         DrawerMenuItem({this.title, this.icon, this.subItemWidget});
       }

Step 8. if you want selected index of drawer menu you can get that in following ways

class HomeScreen extends StatelessWidget {
  final arrDrawerItems = [
    DrawerMenuItem(title: 'Home', icon: Icons.home, subItemWidget: null),
    DrawerMenuItem(
      title: 'Second View',
      icon: Icons.favorite,
      subItemWidget: const Text('13'),
    ),
    DrawerMenuItem(
        title: 'Third View', icon: Icons.search, subItemWidget: null),
  ]; //List for drawer items

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      drawer: DrawerVC(
        arrDrawerItems: arrDrawerItems,
        headerWidget: _buildHeaderForDrawer(context),
        isHeader: true,
        isShowIcon: true,
        textColor: Colors.black,
        selectedTextColor: Colors.amber,
        didItemSelected: (int selectedIndex) {} // Using this function you get selected index of drawer,
      ),
      appBar: AppBar(
          centerTitle: true,
          iconTheme: const IconThemeData(color: Colors.white),
          // You must implement this Consumer<DrawerNavigationProvider> provide for navigation and  you can also get selected index of drawer
          title: Consumer<DrawerNavigationProvider>(
            builder: (ctx, item, child) {
              if (item.selectedIndex == 0) {
                return const Text(
                  'Home',
                  style: TextStyle(color: Colors.white),
                );
              } else if (item.selectedIndex == 1) {
                return const Text('Second View',
                    style: TextStyle(color: Colors.white));
              } else {
                return const Text('Third View',
                    style: TextStyle(color: Colors.white));
              }
            },
          ),
          brightness: Brightness.light),
      body: Center(
      // You must implement this Consumer<DrawerNavigationProvider> provide for navigation and  you can also get selected index of drawer
        child: Consumer<DrawerNavigationProvider>(
              builder: (ctx, item, child) {
                if (item.selectedIndex == 0) {
                  return YOUR_WIDGET();
                } else if (item.selectedIndex == 1) {
                  return YOUR_WIDGET();
                } else {
                  return YOUR_WIDGET();
                }
              },
            ) ??
            const Text('No data'),
      ),
    );
  }
}

Want to Contribute?

  • Created something awesome, made this code better, added some functionality, or whatever (this is the hardest part).
  • Fork it.
  • Create new branch to contribute your changes.
  • Commit all your changes to your branch.
  • Submit a pull request.

Need Help?

If you need help then feel free to contact our Flutter developers.


Collection of Components

We have built many other components and free resources for software development in various programming languages. Kindly click here to view our Free Resources for Software Development.


Changelog

Detailed changes for each release are documented in CHANGELOG.

License

MIT

Keywords

Flutter Drawer Menu, Custom Drawer menu, Side menu, FLutter Slider Menu, Custom Slider, Weblineindia

flutter-drawer's People

Contributors

partners-wli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.