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

套件詳情v1.0.0

pimp_my_button

一個為所有可按壓物件添加迫切需要功能的套件。

近 30 天下載
107
喜歡數
71
Pub 分數
40

安裝套件

flutter pub add pimp_my_button

套件介紹

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

Pimp My Button 是一個 Flutter 套件,可為可按壓的元件增強可自訂的視覺效果、動畫與回饋。它為按鈕及其他互動元件增添『改裝』風格的外觀與感受,使其更具吸引力且視覺上更吸引人。專為尋求在不需複雜自訂程式碼的情況下提升使用者介面美學的開發者設計,此套件可輕鬆整合至現有的 Flutter 專案中。該套件透過細微卻具影響力的觸控回應與動態樣式選項,著重於提升使用者體驗。

適用情境

  • 增強移動應用中的按鈕視覺效果
  • 為用戶互動添加動畫反饋
  • 提升遊戲或儀表板中的使用者介面參與度
  • 創造有趣或品牌化的互動元素
  • 使用最少的程式碼自訂可按壓小工具

主要特色

  • 動畫按壓效果
  • 可自定義的視覺反饋
  • 與現有組件的輕鬆整合
  • 支援各種可按壓元件
  • 輕量且高效

適合對象

  • 希望增添亮點的UI設計師
  • 開發互動式原型的開發者
  • 專注於使用者參與的應用程式
  • 遊戲或創意應用
  • 優先進行快速UI改進的團隊

使用建議

  • 僅限可按壓的組件
  • 不支援非Flutter平台
  • 可能需要額外的樣式來適應複雜佈局
  • 不適合用於可存取性要求高的應用程式
  • 依賴外部動畫程式庫

原始 README

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

Showcase

pimp_my_button-showcase

Features

  • Highly customizable (Don't like my particle effects? Make your own with little effort!)
  • Very easy to use
  • A lot of premade particles

Installation

I will publish this package on pub if people enjoy it. So leave a star if you do ;)

dependencies:
  pimp_my_button: ^1.0.0

run packages get and import it

import 'package:pimp_my_button/pimp_my_button.dart';

If you are not able to import it, restart your IDE see: https://github.com/flutter/flutter/issues/17016

Basics

The basic setup looks like this:

PimpedButton(
  particle: DemoParticle(),
  pimpedWidgetBuilder: (context, controller) {
    return FloatingActionButton(onPressed: () {
      controller.forward(from: 0.0);
    },);
  },
);

The pimpedWidgetBuilder uses a builder which besides providing a new context and an AnimationController. When your button is pressed call this code:

controller.forward(from: 0.0);

It's important to include the from field because otherwise the animation won't play after the first tap.

The particle specified in the PimpedButton controlls what the animation looks like.

Demo Particle Walk Through

We'll walk through how to build a Particle yourself, step by step.

Here is what were are going to build:

fab

Each particle has to extend Particle and override this method: void paint(Canvas canvas, Size size, progress, seed)

  • Canvas is the canvas you can paint on
  • The size is the bounding box of the the enclosing widget
  • Progress is a double between 0 and 1, it reflects the progress in the animation
  • The seed is an int value generated once for every tap. When dealing with randoms, initialize your Random with that seed (so every frame is synced)

The first particle

CompositeParticle(
  children: []
).paint(canvas, size, progressm seed);

You have to paint atleast one Particle in the paint(.,.,.,) method. Usually this would be the CompositeParticle.

The CompositeParticle doesn't do much on its own. It only paints all of its children.

Adding actual particles

The next interesting particle is the CircleMirror and RectangeMirror.

    CircleMirror(
        numberOfParticles: 6,
        child: AnimatedPositionedParticle(
          begin: Offset(0.0, 20.0),
          end: Offset(0.0, 60.0),
          child: FadingRect(width: 5.0, height: 15.0, color: Colors.pink),
        ),
        initialRotation: -pi / randomMirrorOffset),

This mirrors its particle around the middle point in a circular shape. In this case you provide one Particle which is going to be drawn multiple times, thus looking identical. If you want different particles (or the same with randomized values), use the CircleMirror.builder.

At the bottom of the hierarchy is the FadingRect, all it does is drawing a rectangle which fades out over time. To make it move, it's wrapped in an AnimatedPositionedParticle.

This is the full code:

class DemoParticle extends Particle {
  @override
  void paint(Canvas canvas, Size size, progress, seed) {
    Random random = Random(seed);
    int randomMirrorOffset = random.nextInt(8) + 1;
    CompositeParticle(children: [
      Firework(),
      CircleMirror(
          numberOfParticles: 6,
          child: AnimatedPositionedParticle(
            begin: Offset(0.0, 20.0),
            end: Offset(0.0, 60.0),
            child: FadingRect(width: 5.0, height: 15.0, color: Colors.pink),
          ),
          initialRotation: -pi / randomMirrorOffset),
      CircleMirror.builder(
          numberOfParticles: 6,
          particleBuilder: (index) {
            return IntervalParticle(
                child: AnimatedPositionedParticle(
                  begin: Offset(0.0, 30.0),
                  end: Offset(0.0, 50.0),
                  child: FadingTriangle(
                      baseSize: 6.0 + random.nextDouble() * 4.0,
                      heightToBaseFactor: 1.0 + random.nextDouble(),
                      variation: random.nextDouble(),
                      color: Colors.green),
                ),
                interval: Interval(
                  0.0,
                  0.8,
                ));
          },
          // division by 0 is not good ;)
          initialRotation: -pi / randomMirrorOffset + 8),
    ]).paint(canvas, size, progress, seed);
  }
}

Notes

Some particles worth checking out:
  • IntervalParticle, applies an interval and/or curve to the child.
  • FourRandomSlotParticle, positions 4 children on the different sections.
  • PoppingCircle, pretty popping circle
Check out other demo particles:

https://github.com/Norbert515/pimp_my_button/blob/master/lib/src/demo_particles.dart

You are not restricted to use the particles in the context of "Pimp my button", the particles can be drawn on any regular canvas.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。