搜索插件、代码仓与 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.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。