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

local_hero 封面
插件详情v0.3.0

local_hero

一个当其在同一路由内的位置发生变化时,会隐式启动英雄动画的部件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1.2万
喜欢数
274
Pub 分数
150

安装插件

flutter pub add local_hero

插件介绍

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

local_hero 包在小部件的位置在同一路由内发生变化时,启用隐式英雄动画。它通过自动动画化小部件从旧位置到新位置的移动,简化了过渡效果,以流畅的视觉流程提升用户体验。适用于单个屏幕内的导航或动态 UI 更新,可在 Android、iOS、Web、macOS、Windows 和 Linux 等所有主要平台上运行。该包轻量且与 Flutter 现有的动画系统无缝集成。

适合场景

  • 单个路由内的平滑屏幕过渡
  • 在状态更改期间动画化小部件重新定位
  • 增强动态列表中的UI反馈
  • 创建直观的导航体验
  • 支持响应式布局偏移
  • 提高交互式应用中的视觉连续性

主要特点

  • 位置更改时的自动英雄动画
  • 与 Flutter 动画系统的无缝集成
  • 跨平台支持
  • 所需的样板代码最少
  • 仅在同一路由内有效
  • 补充现有的 Hero 小部件

适合对象

  • 开发交互式 UI 的开发者
  • 需要流畅过渡的应用程序
  • 注重用户体验一致性的团队
  • 使用动态布局的项目
  • Flutter 初学者学习动画
  • 频繁重新定位控件的应用程序

使用建议

  • 限于同路由动画
  • 不支持跨路由过渡
  • 需要谨慎放置以避免意外行为
  • 不适合复杂的多屏幕导航
  • 如果过度使用,可能会影响性能
  • 最好与稳定的 widget 键一起使用

原始 README

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

local_hero

Pub

A widget which implicitly launches a hero animation when its position changed within the same route.

Overview

Getting started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  local_hero:

In your library add the following import:

import 'package:local_hero/local_hero.dart';

Usage

To be animated implicitly, a widget needs to be surrounded by a LocalHero widget with a unique tag:

const LocalHero(
    tag: 'my_widget_tag',
    child: MyWidget(),
),

A LocalHero widget must have a LocalHeroScope ancestor which hosts the animations properties (duration, curve, etc.). At each frame we must have only one LocalHero per tag, per LocalHeroScope.

The following example shows the basic usage of a LocalHero widget:

class _LocalHeroPage extends StatelessWidget {
  const _LocalHeroPage({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: LocalHeroScope(
          duration: const Duration(milliseconds: 300),
          curve: Curves.easeInOut,
          child: const _LocalHeroPlayground(),
        ),
      ),
    );
  }
}

class _LocalHeroPlayground extends StatefulWidget {
  const _LocalHeroPlayground({
    Key key,
  }) : super(key: key);

  @override
  _LocalHeroPlaygroundState createState() => _LocalHeroPlaygroundState();
}

class _LocalHeroPlaygroundState extends State<_LocalHeroPlayground> {
  AlignmentGeometry alignment = Alignment.topLeft;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          child: Padding(
            padding: const EdgeInsets.all(8),
            child: Align(
              alignment: alignment,
              child: const LocalHero(
                tag: 'id',
                child: _Box(),
              ),
            ),
          ),
        ),
        RaisedButton(
          onPressed: () {
            setState(() {
              alignment = alignment == Alignment.topLeft
                  ? Alignment.bottomRight
                  : Alignment.topLeft;
            });
          },
          child: const Text('Move'),
        ),
      ],
    );
  }
}

class _Box extends StatelessWidget {
  const _Box({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.red,
      width: 50,
      height: 50,
    );
  }
}

Example

Sponsoring

I'm working on my packages on my free-time, but I don't have as much time as I would. If this package or any other package I created is helping you, please consider to sponsor me so that I can take time to read the issues, fix bugs, merge pull requests and add features to these packages.

Changelog

Please see the Changelog page to know what's recently changed.

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目