搜索插件、代码仓与 APP 分类

drawerbehavior 封面
插件详情v3.0.4

drawerbehavior

Drawer behavior 是一个库,可为抽屉提供额外的行为,例如在抽屉滑动时移动视图或缩放视图的高度。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
323
喜欢数
168
Pub 分数
150

安装插件

flutter pub add drawerbehavior

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

DrawerBehavior 是一个 Flutter 包,通过在滑动过程中启用动态视觉效果(例如移动或缩放内容视图的高度)来增强抽屉功能。它提供了流畅、交互式的过渡效果,提升了导航密集型应用的用户体验。专为希望对抽屉交互拥有更多控制权的开发者设计,可与标准 Drawer 小部件无缝集成。该库支持 Android、iOS、Web、macOS、Windows 和 Linux 多个平台,适用于跨平台应用开发。

适合场景

  • 增强抽屉动画
  • 创建身临其境的导航体验
  • 提高用户界面响应速度
  • 自定义抽屉交互效果
  • 构建现代应用程序界面

主要特点

  • 抽屉滑动时的动态视图移动
  • 内容视图的高度缩放
  • 跨平台兼容性
  • 与现有抽屉的轻松集成
  • 平滑、可自定义的过渡效果

适合对象

  • 开发复杂导航模式的开发者
  • 注重设计的Flutter应用
  • 需要动画抽屉交互的应用
  • 跨平台移动和Web项目
  • UI/UX增强专家

使用建议

  • 可能需要额外的性能调优
  • 可用文档有限
  • 最适合频繁使用抽屉的应用程序
  • 与其他手势检测器的潜在冲突
  • 需要理解手势和动画原理

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

pub package

All Contributors

Drawer Behavior - Flutter

Drawer Behavior is a Flutter library that provides advanced effects and behaviors for the side navigation drawer. Unlike the standard Flutter drawer, this package allows you to create immersive interactions such as moving the view, scaling the view's height, or adding 3D effects while the drawer slides.

Alt Text

✨ Features

  • Scale Effect: smoothly scales down the main content as the drawer opens.

  • 3D Effect: Adds a rotation depth effect to the main content.

  • Multi-Directional: Supports both Left and Right side drawers.

  • Peek Drawer: Keep a portion of the drawer visible even when closed.

  • Customization: Full control over headers, footers, item builders, and animations.

  • Null-Safety: Fully supports Dart null-safety.

📦 Installation

Add this to your package's pubspec.yaml file:

dependencies:
  drawerbehavior: ^3.0.0 # Check pub.dev for the latest version

Install it via command line:

flutter pub get

🚀 Usage

1. Import the package
import 'package:drawerbehavior/drawerbehavior.dart';
2. Basic Implementation

Replace your standard Scaffold with DrawerScaffold. Define your drawers using SideDrawer and your main content using the builder.

import 'package:flutter/material.dart';
import 'package:drawerbehavior/drawerbehavior.dart';

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int selectedMenuItemId = 0;

  // Define your menu items
  final Menu menu = Menu(
    items: [
      MenuItem(id: 0, title: 'Home', icon: Icons.home),
      MenuItem(id: 1, title: 'Profile', icon: Icons.person),
      MenuItem(id: 2, title: 'Settings', icon: Icons.settings),
    ],
  );

  @override
  Widget build(BuildContext context) {
    return DrawerScaffold(
      // App Bar handles the menu button automatically
      appBar: AppBar(
        title: Text("Drawer Behavior"),
      ),
      
      // Define the drawer(s)
      drawers: [
        SideDrawer(
          percentage: 0.6, // Scale the main view down to 60%
          menu: menu,
          direction: Direction.left,
          animation: true,
          color: Theme.of(context).primaryColor,
          selectedItemId: selectedMenuItemId,
          onMenuItemSelected: (itemId) {
            setState(() {
              selectedMenuItemId = itemId;
            });
          },
        )
      ],
      
      // Build the main screen content based on selection
      builder: (context, id) => IndexedStack(
        index: selectedMenuItemId,
        children: [
          Center(child: Text("Home Page")),
          Center(child: Text("Profile Page")),
          Center(child: Text("Settings Page")),
        ],
      ),
    );
  }
}

🎨 Customization

You can fine-tune the look and feel using parameters in DrawerScaffold and SideDrawer.

DrawerScaffold Options
Parameter Description
drawers A list of SideDrawer widgets (e.g., left and right).
builder Builder for the main content area. Use this to react to state changes.
defaultDirection The default direction (left/right) controlled by the toggle button.
cornerRadius Radius of the main content's corners when the drawer is open.
contentShadow Shadow definition for the main content panel.
enableGestures Boolean to enable/disable drag gestures.
onSlide Callback triggered while the drawer is sliding.
controller DrawerScaffoldController for programmatic control (open/close).
SideDrawer Options
Parameter Description
percentage How much the main content scales down (e.g., 0.8) when open.
degree The rotation degree for the 3D effect (between 15 and 45).
slide If true, the main content slides horizontally with the drawer.
peekMenu If true, a small part of the drawer remains visible when closed.
peekSize The width of the drawer when peekMenu is active.
direction Direction.left or Direction.right.
headerView Widget to display at the top of the drawer.
footerView Widget to display at the bottom of the drawer.
itemBuilder Custom builder for menu items if you don't want the default look.
color Background color of the drawer.
background Background DecorationImage for the drawer.

🔄 Migration Guide

If you are upgrading from older versions, please note the following breaking changes:

v2.0 to v3.0 (Null-safety & API Cleanup)
  1. DrawerScaffold:

    • mainDrawer property is now defaultDirection.

    • percentage property moved inside SideDrawer.

    • contentView is now builder.

  2. SideDrawer:

    • menuView is now replaced by the drawers list containing SideDrawer.

Example:

// OLD
DrawerScaffold(
  mainDrawer: Direction.left,
  contentView: Screen(...),
  percentage: 0.6,
  menuView: MenuView(...),
)

// NEW
DrawerScaffold(
  defaultDirection: Direction.left,
  builder: (context, id) => ...,
  drawers: [
    SideDrawer(
      percentage: 0.6,
      ...
    )
  ],
)

📱 Previews

Scale Effect
DrawerScaffold(
  drawers: [
    SideDrawer(
      percentage: 0.6,
      // ...
    )
  ],
  // ...
);

Right Drawer
DrawerScaffold(
  drawers: [
    SideDrawer(
      direction: Direction.right,
      // ...
    )
  ],
  // ...
);

3D Effect
DrawerScaffold(
  drawers: [
    SideDrawer(
      degree: 45,
      // ...
    )
  ],
  // ...
);

Drawer with Header
```dart DrawerScaffold( headerView: headerView(context), // ... );

### Drawer with Footer

<img src="https://github.com/shiburagi/Drawer-Behavior-Flutter/blob/preview/preview-ios-4.png?raw=true" width="200px"/>

```dart
DrawerScaffold(
  footerView: footerView(context),
  // ...
);

Drawer with Header and Custom Builder
DrawerScaffold(
  headerView: headerView(context),
  drawers: [
    SideDrawer(
      itemBuilder: (BuildContext context, MenuItem menuItem, bool isSelected) {
        return Container(
          color: isSelected ? Theme.of(context).colorScheme.secondary.withOpacity(0.7) : Colors.transparent,
          padding: EdgeInsets.fromLTRB(24, 16, 24, 16),
          child: Text(
            menuItem.title,
            style: Theme.of(context).textTheme.subtitle1?.copyWith(
              color: isSelected ? Colors.black87 : Colors.white70),
          ),
        );
      }
    )
  ],
  // ...
);

Peek Drawer
DrawerScaffold(
  headerView: headerView(context),
  drawers: [
    SideDrawer(
      peekMenu: true,
      percentage: 1,
      menu: menuWithIcon,
      direction: Direction.left,
    )
  ],
  // ...
);

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Based on the original work by shiburagi.

Contributors

trademunch
trademunch

💻
anjarnaufals
anjarnaufals

💻
Vladimir Vlach
Vladimir Vlach

💻
Chris Hayen
Chris Hayen

💻

所属分类

源码仓库

使用此插件的项目

暂无相关数据。