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.