搜尋套件、儲存庫與 APP 分類

flutter_expandable_fab 封面
套件詳情v3.0.0

flutter_expandable_fab

可動畫顯示和隱藏多個操作按鈕的浮動操作按鈕 (FAB) 速撥。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
3.2萬
喜歡數
448
Pub 分數
160

安裝套件

flutter pub add flutter_expandable_fab

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,提供帶有動畫效果的速度撥號浮動操作按鈕(FAB),允許使用者透過平滑過渡展開和收起多個操作按鈕。它透過一種緊湊且基於手勢的方式,為使用者提供從單一 FAB 訪問多個操作的互動體驗,進而增強 UI 的互動性。此套件支援所有主要平台,並專為行動與網頁應用中的直覺導航而設計。可自訂的動畫與定位設定,使其適用於現代、動態的介面。

適用情境

  • 帶有多个操作的底部導航
  • 上下文操作選單
  • 行動應用程式的增強型使用者介面
  • 快速存取常見功能
  • 網頁上的互動式設計元素
  • 生產力應用中的流程優化

主要特色

  • 平滑的展開/收合動畫
  • 可自定義的按鈕位置
  • 支援多個動作項目
  • 跨平台相容性
  • 與現有 UI 的輕鬆整合
  • 可設定的動畫持續時間與曲線

適合對象

  • 開發互動式移動應用的開發者
  • 尋求動態 FAB 解決方案的設計人員
  • 使用 Flutter 進行跨平台專案的團隊
  • 需要上下文操作面板的應用程式
  • 以使用者體驗為導向的應用開發
  • 強調基於手勢互動的專案

使用建議

  • 包含多個操作按鈕時可能影響效能
  • 需要仔細的佈局規劃
  • 動畫行為可能因平台而異
  • 不適合簡單的單動作場景
  • 需要在所有目標平台進行測試
  • 超出基本樣式之外的自訂功能有限

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_expandable_fab

pub package

English, 日本語

flutter_expandable_fab is a speed dial FAB (Floating Action Button) that can animate the display and hiding of multiple action buttons.
It can be configured to display vertically, horizontally, or in a fan-shaped manner, on either side. It allows for fine-grained customization.

Migration from 1.x to 2.x

In version 2.x, I have made changes to enable free customization of the open/close buttons by setting builders.

Code before migration:
ExpandableFab(
  child: const Icon(Icons.account_box),
  foregroundColor: Colors.amber,
  backgroundColor: Colors.green,
  closeButtonStyle: const ExpandableFabCloseButtonStyle(
    child: Icon(Icons.abc),
    foregroundColor: Colors.deepOrangeAccent,
    backgroundColor: Colors.lightGreen,
  )
  expandedFabSize: ExpandedFabSize.small,
  collapsedFabSize: ExpandableFabSize.regular,
  expandedFabShape: const CircleBorder(),
  collapsedFabShape: const CircleBorder(),
)
Code after migration:
ExpandableFab(
  openButtonBuilder: RotateFloatingActionButtonBuilder(
    child: const Icon(Icons.account_box),
    fabSize: ExpandableFabSize.regular,
    foregroundColor: Colors.amber,
    backgroundColor: Colors.green,
    shape: const CircleBorder(),
  ),
  closeButtonBuilder: DefaultFloatingActionButtonBuilder(
    child: const Icon(Icons.close),
    fabSize: ExpandableFabSize.small,
    foregroundColor: Colors.deepOrangeAccent,
    backgroundColor: Colors.lightGreen,
    shape: const CircleBorder(),
  ),
)

Showcase

Fan style & Blur overlay
Vertical style & Color overlay
Horizontal style & Custom buttons
Center Fan style
floatingActionButton: ExpandableFab(
  type: ExpandableFabType.fan,
  pos: ExpandableFabPos.center,
  fanAngle: 180,

Getting started

import 'package:flutter_expandable_fab/flutter_expandable_fab.dart';

Scaffold(
  floatingActionButtonLocation: ExpandableFab.location,
  floatingActionButton: ExpandableFab(
    children: [
      FloatingActionButton.small(
        heroTag: null,
        child: const Icon(Icons.edit),
        onPressed: () {},
      ),
      FloatingActionButton.small(
        heroTag: null,
        child: const Icon(Icons.search),
        onPressed: () {},
      ),
    ],
  ),
),

Open/Close programmatically

class _FirstPageState extends State<FirstPage> {
  final _key = GlobalKey<ExpandableFabState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButtonLocation: ExpandableFab.location,
      floatingActionButton: ExpandableFab(
        key: _key,
        children: [
          FloatingActionButton.small(
            child: const Icon(Icons.edit),
            onPressed: () {
              final state = _key.currentState;
              if (state != null) {
                debugPrint('isOpen:${state.isOpen}');
                state.toggle();
              }
            },
          ),
        ],
      ),
    );
  }
}

Customize

You can customize the open/close buttons with your preferred Widget using FloatingActionButtonBuilder. By using DefaultFloatingActionButtonBuilder, you can easily set up the FloatingActionButton. RotateFloatingActionButtonBuilder provides a FloatingActionButton with a rotating animation. Also, the items specified in children don't necessarily have to be FloatingActionButton; you can set any Widget freely.

ExpandableFab(
  openButtonBuilder: RotateFloatingActionButtonBuilder(
    child: const Icon(Icons.account_box),
    fabSize: ExpandableFabSize.regular,
    foregroundColor: Colors.amber,
    backgroundColor: Colors.green,
    shape: const CircleBorder(),
  ),
  closeButtonBuilder: FloatingActionButtonBuilder(
    size: 56,
    builder: (BuildContext context, void Function()? onPressed,
        Animation<double> progress) {
      return IconButton(
        onPressed: onPressed,
        icon: const Icon(
          Icons.check_circle_outline,
          size: 40,
        ),
      );
    },
  ),
  children: [
    FloatingActionButton.large(
      heroTag: null,
      child: const Icon(Icons.edit),
      onPressed: () {},
    ),
    IconButton(
      onPressed: () {
        final state = _key.currentState;
        if (state != null) {
          debugPrint('isOpen:${state.isOpen}');
          state.toggle();
        }
      },
      icon: const Icon(
        Icons.share,
        size: 30,
      ),
    ),
  ],
)

Since children is an array of widgets, you can place any widget you like, not limited to FloatingActionButton.
You can also create buttons with labels as shown below.

floatingActionButton: ExpandableFab(
  key: _key,
  type: ExpandableFabType.up,
  childrenAnimation: ExpandableFabAnimation.none,
  distance: 70,
  overlayStyle: ExpandableFabOverlayStyle(
    color: Colors.white.withOpacity(0.9),
  ),
  children: const [
    Row(
      children: [
        Text('Remind'),
        SizedBox(width: 20),
        FloatingActionButton.small(
          heroTag: null,
          onPressed: null,
          child: Icon(Icons.notifications),
        ),
      ],
    ),
    Row(
      children: [
        Text('Email'),
        SizedBox(width: 20),
        FloatingActionButton.small(
          heroTag: null,
          onPressed: null,
          child: Icon(Icons.email),
        ),
      ],
    ),
    Row(
      children: [
        Text('Star'),
        SizedBox(width: 20),
        FloatingActionButton.small(
          heroTag: null,
          onPressed: null,
          child: Icon(Icons.star),
        ),
      ],
    ),
    FloatingActionButton.small(
      heroTag: null,
      onPressed: null,
      child: Icon(Icons.add),
    ),
  ],
),

Properties

ExpandableFab
Property Description Default
distance Distance from children 100
duration Animation duration 250ms
fanAngle Angle of opening when fan type 90
initialOpen Open at initial display false
type The type of behavior of this widget fan
pos Position for displaying the widget right
closeButtonBuilder Builder for the close button
openButtonBuilder Builder for the open button
childrenOffset For positioning of children widgets
childrenAnimation Types of animations for Children rotate
children The widgets below this widget in the tree
onOpen Will be called before opening the menu
afterOpen Will be called after opening the menu
onClose Will be called before the menu closes
afterClose Will be called after the menu closes
overlayStyle Provides the style for overlay. No overlay when null.
openCloseStackAlignment Defines how [openButtonBuilder] and [closeButtonBuilder] are aligned in a [Stack] Alignment.center
FloatingActionButtonBuilder
Property Description Default
builder Callback to build the Widget
size Size of the Widget
DefaultFloatingActionButtonBuilder
Property Description Default
fabSize Size of the button regular
foregroundColor Foreground color of the button
backgroundColor Background color of the button
shape Shape of the close button
heroTag Tag to apply to the [Hero] widget of the button
child Child widget of the button
RotateFloatingActionButtonBuilder
Property Description Default
angle Angle of rotation (in radians) math.pi / 2
... Same as DefaultFloatingActionButtonBuilder

Thanks

I referred to the code from this article: https://docs.flutter.dev/cookbook/effects/expandable-fab

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案