contextualactionbar 套件提供了一種實作 Flutter 中上下文操作欄(CAB)的變通方法,可動態取代標準應用程式列,在選取項目時顯示與上下文相關的操作。此套件專為 Android、iOS、Web、macOS、Windows 及 Linux 等多個平台設計,透過在選擇模式下提供針對性控制來提升使用者互動體驗。該套件可無縫整合至現有的 Flutter 應用程式中,並支援自訂樣式與行為。在需要執行批次操作的清單或格狀介面中尤為實用。
適用情境
列表中的批量項目選擇
網格中的上下文相關操作
移動應用中的增強用戶互動
可自定義的操作疊加層
跨平台實現
選擇模式UI增強
主要特色
動態替換應用欄
對多個平台的支援
可自定義的操作按鈕
與選擇模式的整合
輕量且容易實現
適用於所有裝置的響應式設計
適合對象
開發互動式列表介面的開發者
需要批量操作的應用程式
跨平台移動應用
基於選擇的工作流程介面
尋求跨平台CAB解決方案的團隊
需要上下文操作支援的 Flutter 項目
使用建議
需要手動處理選擇狀態
有限的內建動畫
可能需要額外的樣式以保持一致性
依賴於與可滾動元素的正確整合
不適合簡單的靜態UI
最佳搭配狀態管理模式使用
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
Flutter contextual action bar(CAB)
CAB & Flutter
CAB is a top app bar that replace the application app bar to provide contextual actions to selected items. Check the material implementation and requirement here
Flutter does not natively support CAB yet. see issue
Until CAB is natively supported, this package should provide you with an elegant way to implement the contextual action bar in flutter.
How it works
ContextualScaffold
ContextualAppBar
ContextualAction
ContextualActionWidget
ContextualScaffold<?>
The ContextualScaffold<?> is similar to the normal material Scaffold except that it also takes
a required contextualAppBar.
You can provide multiple ContextualScaffold as needed
ContextualAppBar<?>
The ContextualAppBar<?> is similar to the normal material Appbar but takes a counterBuilder instead of title and also a contextualActions instead of actions.
You can use the ContextualActionWidget anywhere in the ContextualActionScaffold body to notify ContextualActionScaffold that an item have been selected in order to show the ContextualAppBar.
Note: It is important that the child widget does not handle onLongPress.
A closer look at ContextualActionWidget<?>
The ContextualActionWidget<?> takes other optional parameters like
selectedColor
selectedWidget
unselectedWidget
The selectedColor is the color of the background for the selected item, it defaults to the splash color, if not provided. The selectedColor works well with ListTile.
selectedWidget and unselectedWidget are stacked on top of the provided child widget. By default, they are positioned at the center of the provided child widget.
Since They are stacked, you can use Row, Align, Positioned Widget or any other combination of widgets to position them where desired.
The selectedWidget is shown when the ActionMode is enabled and the item is selected, while the unselectedWidget is shown when ActionMode is enabled and the item is not selected. See example(status_saver) image below with both the selectedWidget and unselectedWidget aligned to the top-right corner.
ActionMode
This contextual action bar workaround does not support zero item in the ActionMode.
Use the ActionMode.addItem<?> to add an item to the selected items. If this is the first selection, the ActionMode is will be enabled.
Use the ActionMode.addItems<?> to add a list of items.
Use the ActionMode.disable<?> to disable and deselect all selected items.
Use the ActionMode.enabledStream<?> to emit true or false depending on if the Action mode is enabled or disabled respectively.
Note: In most cases, you won't need to use ActionMode.disable<?> because the package already do that for you where needed.
Study complete examples at example page.
If you like the project, don't forget to star ⭐️