搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案