anydrawer 1.0.6 copy "anydrawer: ^1.0.6" to clipboard
anydrawer: ^1.0.6 copied to clipboard

Unleash flexibility in your Flutter app with our package. Display a drawer anywhere, no scaffold needed. Try it now!

Anydrawer #

Pub Version License GitHub issues Very Good Analysis Flutter Dart

Introducing a revolutionary Flutter package that allows you to display a drawer from anywhere within your app, simply by providing context.

Say goodbye to the constraints of using a scaffold to show a drawer.

With this package, you gain the flexibility to display a drawer from any point in your app, enhancing your app's navigation and user experience. Whether you're building a complex app with numerous screens or a simple one with a few, this package is designed to make your development process smoother and your app more user-friendly.

Try it today and experience the difference!

Installation #

To use the anydrawer package in your Flutter project, follow these steps:

  1. Add the dependency to your pubspec.yaml file:

    dependencies:
      anydrawer: ^1.0.6 # Replace with the latest version
    
  2. Run flutter pub get to fetch the package.

Usage #

  1. Import the required packages:

    import 'package:anydrawer/anydrawer.dart';
    
  2. Utilize the showDrawer function to display a customized drawer:

    showDrawer(
      context,
      builder: (context) {
        return const Center(
          child: Text('Left Drawer'),
        );
      },
      config: const DrawerConfig(
        side: DrawerSide.left,
        closeOnClickOutside: true,
        closeOnEscapeKey: true,
        closeOnResume: true, // (Android only)
        closeOnBackButton: true, // (Requires a route navigator)
        backdropOpacity: 0.5,
        borderRadius: 24,
      ),
      onOpen: () {
        // Optional callback when the drawer is opened
      },
      onClose: () {
        // Optional callback when the drawer is closed
      },
      controller: drawerController, // Optional controller to programmatically close the drawer
    );
    

Screenshots #

[]

[]

Parameters #

Parameter Type Description
context BuildContext The build context of the widget that is calling the function.
builder Widget Function(BuildContext) A builder function that returns the widget tree to be displayed inside the drawer.
config DrawerConfig A DrawerConfig object that allows you to customize the behavior and appearance of the drawer.
onOpen void Function() An optional callback that is called when the drawer is opened.
onClose void Function() An optional callback that is called when the drawer is closed.
closeOnEscapeKey bool An optional boolean that determines whether the drawer should close when the Escape key is pressed.
closeOnResume (Android only) bool An optional boolean that determines whether the drawer should close when the app is resumed.
closeOnBackButton bool An optional boolean that determines whether the drawer should close when the back button is pressed.
controller AnyDrawerController A AnyDrawerController object that can be used to programmatically close the drawer.

Note: ⚠️ The controller should be disposed of when it is no longer needed. This can be done by calling the dispose method of the controller. It is not automatically disposed of when the drawer is closed. ⚠️

Note: ⚠️ The closeOnResume is only applicable on Android devices. ⚠️ For closeOnBackButton to work, the app should have a route navigator. If the app does not have a route navigator, it will throw an error.

DrawerConfig has the following properties:

Property Type Description
widthPercentage double Set the width of the drawer as a percentage of the screen width.
maxDragExtent double Set the maximum extent to which the drawer can be dragged open.
side DrawerSide Specify the side from which the drawer should appear (DrawerSide.left or DrawerSide.right).
closeOnClickOutside bool Determine whether the drawer should close when clicking outside of it.
closeOnEscapeKey bool Determine whether the drawer should close when the Escape key is pressed.
closeOnResume bool Determine whether the drawer should close when the app is resumed Android only.
closeOnBackButton bool Determine whether the drawer should close when the back button is pressed Android Only.
dragEnabled bool Allow users to drag the drawer to open and close it.
backdropOpacity double Set the opacity of the backdrop that appears behind the drawer.
borderRadius BorderRadius Adjust the corner radius of the drawer.

I hope this helps! Let me know if you have any further questions.

Animation and Interaction #

The package includes smooth animations and interactive gestures for opening and closing the drawer:

  • Drag the drawer to open or close it (can be disabled using dragEnabled).
  • The drawer smoothly slides in and out from the specified side with customizable animations.

Contributing #

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

TODO #

  • Fix issue with drawer not closing when backbutton is pressed on mobile devices.

License #

This project is licensed under the MIT License.

17
likes
140
pub points
78%
popularity
screenshot

Publisher

verified publishernbhatt.com.np

Unleash flexibility in your Flutter app with our package. Display a drawer anywhere, no scaffold needed. Try it now!

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on anydrawer