搜索插件、代码仓与 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 的互动性。该包支持所有主要平台,并专为移动和 Web 应用中的直观导航而设计。可自定义的动画和位置设置使其适用于现代、动态的界面。

适合场景

  • 带有多个操作的底部导航
  • 上下文操作菜单
  • 移动应用的增强型用户界面
  • 快速访问常用功能
  • 网页上的交互式设计元素
  • 生产力应用中的流程优化

主要特点

  • 平滑的展开/折叠动画
  • 可自定义的按钮位置
  • 支持多个操作项
  • 跨平台兼容性
  • 与现有 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 项

源码仓库

使用此插件的项目