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

confetti 封面
插件详情v0.8.0

confetti

在屏幕上喷洒出五彩缤纷的彩纸。以风格化的方式庆祝应用内的成就。控制彩纸的速度、角度、重力和数量。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
46.4万
喜欢数
1640
Pub 分数
160

安装插件

flutter pub add confetti

插件介绍

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

Confetti 是一个 Flutter 包,可让开发者在其应用中创建生动、动画化的彩带爆发效果。非常适合庆祝成就、里程碑或特殊事件,提供可自定义的效果,包括速度、角度、重力和粒子数量。该包支持多个平台——Android、iOS、Web、macOS、Windows 和 Linux,确保在各种设备上保持一致的视觉魅力。通过 pub add 简单集成,它通过有趣且动态的反馈增强用户参与度。适用于游戏、奖励系统和互动应用时刻。

适合场景

  • 庆祝应用成就
  • 增强游戏胜利屏幕
  • 标记里程碑完成
  • 添加节日用户界面元素
  • 提升奖励中的用户参与度
  • 创建庆祝动画

主要特点

  • 可自定义的彩纸速度
  • 可调节角度和重力
  • 可配置的粒子数量
  • 跨平台支持
  • 与 Flutter 的简单集成
  • 流畅的动画粒子效果

适合对象

  • 游戏开发者
  • 寻求趣味反馈的应用设计者
  • 奖励系统实现者
  • 交互式 UI 创建者
  • Flutter 初学者探索动画
  • 具有成就追踪功能的应用程序

使用建议

  • 可能会影响低端设备的性能
  • 需要仔细调整以获得最佳视觉效果
  • 不适合极简设计风格
  • 超出粒子物理以外的自定义功能有限
  • 应谨慎使用,以避免视觉过载
  • 依赖于平台特定的渲染功能

原始 README

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

Blast some confetti all over the screen and celebrate user achievements!

Demo

Video showing the Confetti in Action: https://youtu.be/dGMVyUY4-6M

Live WEB Demo

An old video walkthrough is available here.

Getting Started

To use this plugin, add confetti as a dependency in your pubspec.yaml file.

See the example to get started quickly. To generate the platform folders run:

flutter create .

in the example folder.

To begin you need to instantiate a ConfettiController variable and pass in a Duration argument. The ConfettiController can be instantiated in the initState method and disposed in the dispose method.

In the build method return a ConfettiWidget. The only attribute that is required is the ConfettiController.

Other attributes that can be set are:

  • blastDirectionality -> an enum value to state if the particles shoot in random directions or a specific direction. BlastDirectionality.explosive will shoot in random directions and don't require a blastDirection to be set. BlastDirectionality.directional requires a blastDirection to specify the direction of the confetti.
  • blastDirection -> a radial value to determine the direction of the particle emission. The default is set to PI (180 degrees). A value of PI will emit to the left of the canvas/screen.
  • emissionFrequency -> should be a value between 0 and 1. The higher the value the higher the likelihood that particles will be emitted on a single frame. Default is set to 0.02 (2% chance)
  • numberOfParticles -> the number of particles to be emitted per emission. Default is set to 10
  • shouldLoop -> determines if the emission will reset after the duration is completed, which will result in continues particles being emitted, and the animation looping
  • maxBlastForce -> will determine the maximum blast force applied to a particle within it's first 5 frames of life. The default maxBlastForce is set to 20
  • minBlastForce -> will determine the minimum blast force applied to a particle within it's first 5 frames of life. The default minBlastForce is set to 5
  • displayTarget -> if true a crosshair will be displayed to show the location of the particle emitter
  • colors -> a list of colors can be provided to manually set the confetti colors. If omitted then random colors will be used. A single color, for example [Colors.blue], or multiple colors [Colors.blue, Colors.red, Colors.green] can be provided as an argument in the `ConfettiWidget
  • strokeWidth optionally set to give a stroke to the paint. Needs to be bigger than 0 to be vissible. Default 0.
  • strokeColor optionally set to give a stroke color. Default black.
  • minimumSize -> a Size controlling the minimum possible size of the confetti. To be used in conjuction with maximumSize. For example, setting a minimumSize equal to Size(10,10) will ensure that the confetti will never be smaller than the specified size. Must be positive and smaller than the maximumSize. Can not be null.
  • maximumSize -> a Size controlling the maximum possible size of the confetti. To be used in conjuction with minimumSize. For example, setting a maximumSize equal to Size(100,100) will create confetti with a size somewhere between the minimum and maximum size of (100, 100) [widht, height]. Must be positive and bigger than the minimumSize, Can not be null.
  • gravity -> change the speed at which the confetti falls. A value between 0 and 1. The higher the value the faster it will fall. Default is set to 0.1
  • particleDrag -> configure the drag force to apply to the confetti. A value between 0 and 1. A value of 1 will be no drag at all, while 0.1, for example, will be a lot of drag. Default is set to 0.05
  • canvas -> set the size of the area where the confetti will be shown, by default this is set to full screen size.
  • createParticlePath -> An optional function that retuns a custom Path to generate unique particles. Default returns a rectangular path.
Example of a custom createParticlePath
Path drawStar(Size size) {
    // Method to convert degree to radians
    double degToRad(double deg) => deg * (pi / 180.0);

    const numberOfPoints = 5;
    final halfWidth = size.width / 2;
    final externalRadius = halfWidth;
    final internalRadius = halfWidth / 2.5;
    final degreesPerStep = degToRad(360 / numberOfPoints);
    final halfDegreesPerStep = degreesPerStep / 2;
    final path = Path();
    final fullAngle = degToRad(360);
    path.moveTo(size.width, halfWidth);

    for (double step = 0; step < fullAngle; step += degreesPerStep) {
      path.lineTo(halfWidth + externalRadius * cos(step),
          halfWidth + externalRadius * sin(step));
      path.lineTo(halfWidth + internalRadius * cos(step + halfDegreesPerStep),
          halfWidth + internalRadius * sin(step + halfDegreesPerStep));
    }
    path.close();
    return path;
  }

Enjoy the confetti.

NOTE: Don't be greedy with the number of particles. The more particles that are on screen the more calculations need to be performed. Performance improvements have been made, however this is still ongoing work. Too many particles will result in performance issues. Use wisely and carefully.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

所在榜单