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

flutter_villains 封面
套件詳情v2.0.0

flutter_villains

Flutter 的反派。只需幾行程式碼即可實現頁面過渡。沒有反派,英雄又算什麼?

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
131
喜歡數
83
Pub 分數
135

安裝套件

flutter pub add flutter_villains

套件介紹

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

Flutter Villains 是一個簡化在 Flutter 應用中建立吸引人的頁面過渡效果的套件,僅需最少的程式碼。受到 Flutter 中「英雄」概念的啟發,它引入了「反派」——在導航過程中移動或變形的動畫元素,增添動態視覺效果。它支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。透過直覺的 API,開發者可以輕鬆提升使用者體驗,實現流暢且富有表現力的過渡效果,無需複雜的實作。非常適合希望藉由精緻動畫脫穎而出的應用。

適用情境

  • 建立動畫頁面過渡
  • 增強應用導航視覺效果
  • 向UI流程添加動態效果
  • 透過動態效果提升使用者參與度
  • 建構視覺豐富的行動與Web應用

主要特色

  • 用於轉場的簡單 API
  • 支援多個平台
  • 平滑的動畫整合
  • 所需最少程式碼
  • 可擴展以自訂效果

適合對象

  • 尋求快速過渡效果的開發者
  • 注重視覺美化的應用程式
  • 以設計為導向的 Flutter 項目
  • 希望減少動畫樣板程式碼的團隊
  • 面向前端的Flutter開發

使用建議

  • 可能會稍微增加套件大小
  • 需要了解 Flutter 的動畫系統
  • 最佳搭配性能感知設計使用
  • 不適合非常簡單的應用
  • 若未與使用者體驗平衡,可能造成過度使用

原始 README

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

license stars forks Pub GitHub followers Twitter Follow Build Status

flutter_villains

What are heroes without villains?

profile-page

(Profile image from: https://unsplash.com/photos/pAs4IM6OGWI)

Check out the article.

What are villains?

You keep seeing beautiful page transitions but you think to yourself those are too much work?

Fear no more, villains are here to save you!

When doing animations when a page transition occurs you'd usally define an AnimationController in the initState() and start it there. You'd also have to wrap your widgets in AnimatedWidgets to react to the AnimationController. Besides this being a lot of boilerplate code which clogs up you precious widgets, animating on exit isn't as trivial.

Using this library you just wrap your widget you'd like to be animated when a page transition occurs in a Villain and everything is handled automatically.

Installation

dependencies:
  flutter_villains: "^1.2.1"

Run packages get and import:

import 'package:flutter_villains/villain.dart';
Assembling pages with style

Define animations to play when a page is opened.

Easy to use
      Villain(
        villainAnimation: VillainAnimation.fromBottom(
          relativeOffset: 0.4,
          from: Duration(milliseconds: 100),
          to: Duration(seconds: 1),
        ),
        animateExit: false,
        secondaryVillainAnimation: VillainAnimation.fade(),
        child: Divider(
          color: Colors.black,
          height: 32.0,
        ),
      ),

That's it. No TickerProviders, no AnimationControllers, no boilerplate, no worries. Remember the StaggeredAnimation tutorial? This is using SequenceAnimation internally and there is therefore no need to specify durations as portions of a time-frame. It just works.

With this basic setup the Divider fades in and moves up when a page transition occures (don't forget the VillainTransitionObserver more on that under Code).

Flexible

The animation you'd like to use is not premade? Make it yourself with a few lines of code!

  static VillainAnimation fade(
          {double fadeFrom = 0.0,
          double fadeTo = 1.0,
          Duration from = Duration.zero,
          Duration to: _kMaterialRouteTransitionLength,
          Curve curve: Curves.linear}) =>
      VillainAnimation(
          from: from,
          curve: curve,
          to: to,
          animatable: Tween<double>(begin: fadeFrom, end: fadeTo),
          animatedWidgetBuilder: (animation, child) {
            return FadeTransition(
              opacity: animation,
              child: child,
            );
          });

Every VillainAnimation needs an Animatable (most of the time it's a Tween) and an AnimatedWidget. Everything else is handled automatically.

Code

There are two way of playing your villains.

  1. If you want them to automatically play when a page transition occurs (you probably want that) then add this to your MaterialApp
    return new MaterialApp(
      navigatorObservers: [new VillainTransitionObserver()],
  1. Play villains in a given context manually.
    VillainController.playAllVillains(context);
Secondary Animation

You can play up to two animations per Villain. You can always wrap Villains inside each other for infinite animations!

    Villain(
      villainAnimation: VillainAnimation.fromBottomToTop(0.4, to: Duration(milliseconds: 150)),
      animateExit: false,
      secondaryVillainAnimation: VillainAnimation.fade,
      child: Text(
        "Hi",
        style: Theme.of(context).textTheme.body1,
      ),
    ),
Extras

Define whether the villain should play on entrance/ exit.

    animateEntrance: true,
    animateExit: true,

When using the VillainController manually, it checks this bool to determine whether it should animate.

  static Future playAllVillains(BuildContext context, {bool entrance = true})

Villains entering the page are decoupled from the page transition, meaning they can be as long as they want. On the other hand, if a villain leaves the page, the animation is driven by the page transition. This means:

  • The exit animation is always as long a the exit page transition
  • Setting the duration doesn't change anything

Examples

Take a look at the example folder for three nice examples.

Features:

The villain framework takes care of:

  • managing page transition callbacks
  • supplying animations
  • providing premade common animations

In contrast to real world villains, these villains are very easy to handle.

Controller

Currenty there are no controllers implemented to play individual villains by themselves. If you'd like to have that implemented I opened an issue discussing it. Check it out!

Icon from https://icons8.com/

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing package code, view the documentation.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。