kf_drawer 是一个 Flutter 包,为跨平台应用提供可自定义的侧边菜单(Drawer)。它提供了简洁轻量的导航实现,支持多种自定义选项,如宽度、动画和项目样式。设计简单易用,可无缝集成到 Android、iOS、Web、macOS、Windows 和 Linux 上的 Flutter 应用中。该包非常适合需要一致且响应式导航抽屉体验的应用。
适合场景
移动应用导航
Web 仪表板侧边栏
桌面应用程序菜单
跨平台导航
可自定义的抽屉布局
主要特点
跨平台兼容性
可自定义抽屉宽度
流畅的动画
轻松集成
对自定义控件的支持
适合对象
开发跨平台应用的开发者
需要一致导航的团队
具有复杂侧边栏需求的应用
以用户界面为重点的项目
快速原型设计
使用建议
有限的内置主题
需要手动样式设置以实现高级设计
无内置暗色模式支持
依赖于 Flutter 的 Drawer API
可能需要额外的状态管理
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
KFDrawer
A dependency-free animated side drawer for Flutter. KFDrawer supports controller
and context-based control, gestures, pinned or centered menus, page history,
right-side drawers, and RTL layouts on every Flutter platform.
Install
dependencies:kf_drawer:^2.1.0
KFDrawer 2.1 supports Dart 3 and Flutter 3.10 or newer. The package is tested
against both its compatibility floor and the current Flutter stable release.
Quick start
Create a controller, give each page item a widget, and place KFDrawer in your
Scaffold body:
footerPinned keeps the footer outside the scrolling item list.
centerScrollableItems centers a shrink-wrapped item list between a fixed
header and footer.
scrollable: false retains the non-scrolling centered column layout.
Right-side and RTL drawers
KFDrawerDirection is logical, so start automatically follows the ambient
text direction:
// Left in LTR, right in RTL (default).KFDrawer(direction: KFDrawerDirection.start)
// Right in LTR, left in RTL.KFDrawer(direction: KFDrawerDirection.end)
Translation, edge dragging, content tap regions, shadow offset, icon padding,
and menu alignment all follow the resolved side.
Dynamic items
Controller changes rebuild the drawer automatically:
drawerController.items = <KFDrawerItem>[...newItems];
drawerController.addItem(newItem);
drawerController.removeItem(oldItem);
drawerController.clearItems();
// If you mutate drawerController.items directly:
drawerController.items.add(newItem);
drawerController.refreshItems();
drawerController.selectItem('settings');
Optional page history and Back handling
KFDrawer swaps page widgets; it does not push Navigator routes. Enable the
lightweight controller history only if this is the behavior your app needs:
Use replacePage to change the current page without adding a history entry and
clearHistory after a navigation reset.
Page item callbacks
When an item has both page and onPressed, KFDrawer now performs both actions:
it selects the page, optionally closes the drawer, and invokes the callback.