flutter_confetti
blast some conf,etti all over the screen and celebrate user achievements!
getting started
to use this plugin, add conf,etti
as a dependency in your pubspec.yaml file.
see the example to get started quickly.
to begin you need to instantiate a conf,etticontroller
variable and pass in a duration
argument. the conf,etticontroller
can be instantiated in the initstate
method and disposed in the dispose
method.
in the build
method return a confe,ttiwidget
. the only attribute that is required is the confe,tticontroller
.
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 ablastdirection
to be set.blastdirectionality.directional
requires ablastdirection
to specify the direction of the confetti.blastdirection
-> a radial value to determine the direction of the particle emission. the default is set topi
(180 degrees). a value ofpi
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 to0.02
(2% chance)numberofparticles
-> the number of particles to be emitted per emission. default is set to10
shouldloop
-> determines if the emission will reset after the duration is completed, which will result in continues particles being emitted, and the animation loopingmaxblastforce
-> will determine the maximum blast force applied to a particle within it’s first 5 frames of life. the defaultmaxblastforce
is set to20
minblastforce
-> will determine the minimum blast force applied to a particle within it’s first 5 frames of life. the defaultminblastforce
is set to5
displaytarget
-> iftrue
a crosshair will be displayed to show the location of the particle emittercolors
-> 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 `confettiwidgetminimumsize
-> asize
controlling the minimum possible size of the confetti. to be used in conjuction withmaximumsize
. for example, setting aminimumsize
equal tosize(10,10)
will ensure that the confetti will never be smaller than the specified size. must be positive and smaller than themaximumsize
. can not be null.maximumsize
-> asize
controlling the maximum possible size of the confetti. to be used in conjuction withminimumsize
. for example, setting amaximumsize
equal tosize(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 theminimumsize
, 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 to0.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 to0.05
canvas
-> set the size of the area where the confetti will be shown, by default this is set to full screen size.
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.
Comments are closed.