搜索插件、代码仓与 APP 分类

插件详情v0.5.3

follow_the_leader

跟随其他小部件的组件。

AndroidiOS
近 30 天下载
4万
喜欢数
37
Pub 分数
150

安装插件

flutter pub add follow_the_leader

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,可使小部件动态跟随屏幕上其他小部件的位置。它非常适合创建交互式 UI 元素,如工具提示、浮动指示器或跟踪目标小部件移动的动画叠加层。该包以性能和简单性为核心设计,可在 Android 和 iOS 平台上无缝运行。该包高效利用 Flutter 的渲染管道,确保流畅动画且无卡顿。非常适合希望借助响应式视觉反馈提升用户体验的开发者。

适合场景

  • 创建动态提示
  • 构建跟踪内容的浮动操作按钮
  • 设计动画叠加层
  • 实施引导式游览
  • 可视化光标或选择路径

主要特点

  • 实时小部件跟踪
  • 平滑的动画集成
  • 跨平台兼容性
  • 最小化样板代码
  • 高效渲染,开销最小

适合对象

  • 寻求交互元素的UI/UX设计师
  • 开发人员构建引导式入门流程
  • 需要动态视觉反馈的应用程序
  • 专注于打造精致移动体验的团队

使用建议

  • 跟踪大量 Widget 时可能影响性能
  • 需要仔细定位以避免重叠
  • 不适用于静态布局
  • 需要在低端设备上进行测试
  • 最好与轻量级目标控件一起使用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Follow the Leader - Widgets following widgets

Built by the Flutter Bounty Hunters


Getting Started

Select a widget that you want to follow and wrap it with a Leader widget. Give the Leader widget a LeaderLink, to share with Followers.

Leader(
  link: _leaderLink,
  child: YourLeaderWidget(),
);

Add a widget that you want to follow your Leader, and wrap it with a Follower widget.

// Follower appears 20px above the Leader.
Follower.withOffset(
  link: _leaderLink,
  offset: const Offset(0, -20),
  leaderAnchor: Alignment.topCenter,
  followerAnchor: Alignment.bottomCenter,
  child: YourFollowerWidget(),
);

Follower's can position themselves with a constant distance from a Leader using .withOffset(), as shown above. Or, Follower's can choose their exact location on every frame by using .withAligner().

// Follower appears where the aligner says it should.
Follower.withAligner(
  link: _leaderLink,
  aligner: _aligner,
  child: YourFollowerWidget(),
);

To constrain where your Follower is allowed to appear, pass a boundary to your Follower.

// Follower is constrained by the given boundary.
Follower.withAligner(
  link: _leaderLink,
  aligner: _aligner,
  boundary: _boundary,
  child: YourFollowerWidget(),
);

Building multiple widgets without layouts

Building follower widgets is a bit unusual with Flutter. Typically, whenever we build multiple widgets in Flutter, we place them in a layout container, such as Column, Row, or Stack. But follower widgets don't respect ancestor layout rules. That's the whole point.

follow_the_leader introduces a new container widget, which builds children, but doesn't attempt to apply any particular layout rules. The primary purpose of this widget is to make it clear to readers that you aren't trying to layout the children.

BuildInOrder(
  children: [
    MyContentWithALeader(),
    Follower.withOffset(),
    Follower.withDynamics(),
  ],
);

The BuildInOrder widget builds each child widget in the order that it's provided. This fact is important because Leader widgets must be built before their Followers. But BuildInOrder does not impose any Offset on its children. BuildInOrder passes its parent's constraints down to the children.

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目