The Drawer Manager class has the ability to swap Scaffold body contents, using a custom provider

Overview

The Drawer Manager class has the ability to swap Scaffold body contents, using a custom provider.

Open Drawer

Hello, Flutter!

Counter

The MAC

All Pages

Features

The Drawer Manager is similar to the Android Drawer, in that it swaps out Widgets (like Android Fragments). It does this by notifying the Scaffold body of the changes needed for your selection, using the DrawerManagerProvider's body property. This approach allows for a cleaner development experience.

    const drawerSelections = [
      HelloPage(),
      CounterPage(),
      TheMACPage()
    ];

    final manager = Provider.of<DrawerManagerProvider>(context, listen: false);

    return Scaffold(
        appBar: AppBar(title: "Some App Bar Title"),
        body: manager.body,
        drawer: DrawerManager(
            ...
            tileSelections: drawerSelections
        )
    )

Note: Similar to Flutter's TextEditingController, the Drawer Manager uses Provider's ChangeNotifier as a parent class to manage user selection by displaying the Widget selection.

Getting started

Install Provider and Drawer Manager

  flutter pub get provider
  flutter pub get drawer_manager

Or install Provider and Drawer Manager (in pubspec.yaml)

    
dependencies:
  flutter:
    sdk: flutter

    ...
  provider: 6.0.2
  drawer_manager: 0.0.3

Import Drawer Manager & Provider

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:drawer_manager/drawer_manager.dart';
    ...

Add DrawerManagerProvider as MaterialApp ChangeNotifierProvider

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<DrawerManagerProvider>(
        create: (_) => DrawerManagerProvider(),
        child: MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(primarySwatch: Colors.blue),
          home: const MyHomePage(),
        )
    );
  }

Usage

Set up drawer selections

    const drawerSelections = [
      HelloPage(),
      CounterPage(),
      TheMACPage()
    ];

Set up drawer manager

The Drawer Manager is able to manage the selections with the DrawerTile class.

        drawer: DrawerManager(
            context: context,
            drawerElements: [
                const DrawerHeader(
                    child: Padding(
                        padding: EdgeInsets.only(bottom: 20),
                        child: Icon(Icons.account_circle),
                    ),
                ),
                DrawerTile(
                    context: context,
                    leading: const Icon(Icons.hail_rounded),
                    title: Text('Hello'),
                    onTap: () async {
                        // RUN A BACKEND Hello, Flutter OPERATION
                    },
                ),
                ...
            ],
            tileSelections: drawerSelections
        )

Note: The DrawerTile class is a child of ListTile, but has a required on onTap attribute, to maintain the selection order. The first DrawerTile will align with the first drawer selection. You can have more selections than tiles, but not more DrawerTiles than selections.

Alternate Usage

Alternatively, you can use a Column, or a ListView for drawer elements, to easily adapt Drawer Manager into existing Drawer implementations.

Use With a Column Widget

        drawer: DrawerManager(
            context: context,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                  ...
              ]
            )
        )

Use With a ListView Widget

        drawer: DrawerManager(
            context: context,
            child: ListView(
              children: [
                  ...
              ]
            )
        )

Additional information

To support this repo, take a look at the SUPPORT.md file.

To view the documentation on the package, follow this link

You might also like...

Body Mass Index (BMI) - a person’s weight in kilograms divided by the square of height in meters

Body Mass Index (BMI) - a person’s weight in kilograms divided by the square of height in meters

Body Mass Index (BMI) is a person’s weight in kilograms divided by the square of height in meters. A high BMI can indicate high body fatness. BMI screens for weight categories that may lead to health problems, but it does not diagnose the body fatness or health of an individual.

Dec 3, 2022

Body Mass Index(BMI) Calculator Android App

Body Mass Index(BMI) Calculator Android App

Body Mass Index(BMI) Calculator Android App Body Mass Index(BMI) Calculator Android App Getting Started This project is a starting point for a Flutter

Sep 9, 2022

LiveLine - A Health Monitoring/Awareness/Risk-Alert App which will display a Person's Heart rate, SpO2 level concentration and Body Temperature

LiveLine  - A Health Monitoring/Awareness/Risk-Alert App which will display a Person's Heart rate, SpO2 level concentration and Body Temperature

A Health Monitoring/Awareness/Risk-Alert App which will display a Person's Heart rate, SpO2 (oxygen% in the body) level concentration and Body Temperature

Jun 7, 2022

Best ever drawer in flutter for android and ios

Best ever drawer in flutter for android and ios

Drawer in Flutter Best ever drawer in flutter to make precious application. This flutter app is made just to demonstrate how you we can make an animat

Oct 16, 2022

GETX 2.13.1 COMMON CLASS

ecommerce export PATH="$PATH:/Users/mac/Documents/flutter/bin" shopping use total price count num get totalPrice = items.fold(0, (total, current) =

Jan 30, 2022

An application of learning outcomes from the Mastering Flutter 2.0 class: Building Travel and Aircraft Applications Buildwithangga

An application of learning outcomes from the Mastering Flutter 2.0 class: Building Travel and Aircraft Applications Buildwithangga

An application of learning outcomes from the Mastering Flutter 2.0 class: Building Travel and Aircraft Applications Buildwithangga

Aug 29, 2022

Custom Gesture Detector for Flutter. Empower your users with custom gestures.

Gestures Custom Gesture Detector for Flutter. Empower your users with custom gestures. How to use In your pubspec.yaml: dependencies: gestures: ^1.0

Nov 4, 2022

🎡 Elegant music app to play local music & YouTube music. Distributes music into albums & artists. Has playlists & lyrics.

🎡 Elegant music app to play local music & YouTube music. Distributes music into albums & artists. Has playlists & lyrics.

Harmonoid Elegant music app to play local music & YouTube music. Download Now 🏁 Feel free to report bugs & issues. We'll be there to fix. Loving the

Dec 30, 2022

This is a smart farming app which helps farmers to remotely monitor their crop and take necessary actions. It also has a feature called disease detection.

Smart-Farming-App This is a smart farming app which helps farmers to remotely monitor their crop and take necessary actions. It has features called di

Jul 9, 2022
Comments
  • Fix for issue

    Fix for issue "Reloading duplicates the onTaps"

    Issue Link: https://github.com/the-mac/drawer_manager/issues/1#issue-1177587391

    This pull request allows for reloading the app without triggering the following assertion:

    Failed assertion: line 210 pos 12: 'drawerTileCount <= drawerSelectionCount'
    
    
        var drawerSelectionCount = tileSelections.length;
        final drawerTileCount = dmProvider.onTapFunctions.length;
        
        final drawerTileCountErrorMessage = 'The DrawerTile count is more than the drawer selections. Check that your DrawerTiles ($drawerTileCount), and your selections ($drawerSelectionCount) match.';
        assert(drawerTileCount <= drawerSelectionCount, drawerTileCountErrorMessage);
    
    
    opened by non-profit-lynn 0
  • Reloading duplicates the onTaps

    Reloading duplicates the onTaps

    When reloading the app it duplicates the onTaps, and crashes the application.

    ══║ EXCEPTION CAUGHT BY WIDGETS LIBRARY β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
    The following assertion was thrown building MyHomePage(dirty, state: _MyHomePageState#b0e0f):
    The DrawerTile count is more than the drawer selections. Check that your DrawerTiles (6), and your
    selections (3) match.
    'package:drawer_manager/drawer_manager.dart':
    Failed assertion: line 210 pos 12: 'drawerTileCount <= drawerSelectionCount'
    
    The relevant error-causing widget was:
      _InheritedProviderScope<DrawerManagerProvider?>
      _InheritedProviderScope:file:///usr/local/Caskroom/flutter/2.8.1/flutter/.pub-cache/hosted/pub.dartlang.org/provider-6.0.2/lib/src/inherited_provider.dart:161:12
    

    This happens when I call reassembleApplication and when I type r (for reload) while running a flutter app:

    WidgetsBinding.instance!.reassembleApplication();
    
    opened by non-profit-lynn 0
Owner
The Mobile Applications Community
The Mobile Applications Community is where apps can be built using community resources.
The Mobile Applications Community
A bot to swap instantly tokens using PancakeSwap smart contracts

Swap Pancake Bot Swap Pancake Bot foi feito para fazer swaps instantΓ’neos sem ne

Lucas Almeida 5 Jan 6, 2022
E-Studying-V1 - Flutter application where you can download files from an api and unarchive them and open them and see their contents

E-Studying-V1 - Flutter application where you can download files from an api and unarchive them and open them and see their contents

Chakib Ammar Aouchiche 0 Jan 20, 2022
This design has been created for educational purposes. Also this project has integrated push notifications with firebase and my own server in python.

Ui Clone of the Nequi application This design has been created for educational purposes. Also this project has integrated push notifications with fire

Juan Suarez 3 Nov 17, 2022
I did a task manager which has abilities like (priority,sort,daily,weekly,monthly,profile screen,user auth)

task_manager A task manager app by Flutter. Getting Started This is a task manager app which you can manage your daily/weekly/monthly tasks. Users can

Yusuf Erarslan 2 Jan 12, 2022
A Flutter package with custom implementation of Drawer

Flutter Zoom Drawer A Flutter package with custom implementation of the Side Menu (Drawer) Getting Started To start using this package, add flutter_zo

null 335 Dec 22, 2022
Timer based on provider state manager

timer_provider Timer based on provider state manager Getting Started This project is a starting point for a Flutter application. A few resources to ge

null 4 Aug 10, 2022
Munem Sarker 1 Jan 25, 2022
Mibos App. Mind, Body, and Spirit Health

second_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if th

Shalom Sims 1 Oct 27, 2021
Imc flutter - A flutter app to calculate a body mass index

Imc flutter - A flutter app to calculate a body mass index

Wesley Barbosa 1 Jan 22, 2022
BMI Calculator a Body Mass Index(BMI) calculator app developed with Flutter

BMI Calculator Flutter BMI Calculator is a Body Mass Index(BMI) calculator app developed with Flutter. Currently, the BMI is calculated using Metric u

zahra khoshdel 4 Apr 26, 2022