Implement the ConfettiWidget
masterTo use the confetti effect, follow these steps:
- Instantiate a
ConfettiController: Create aConfettiControllervariable and pass in aDurationargument. It is recommended to instantiate this in yourinitStatemethod and calldispose()in yourdisposemethod to prevent memory leaks. - Add the
ConfettiWidget: In yourbuildmethod, return aConfettiWidget. The only required attribute is theConfettiController.
Note: Avoid using an excessive number of particles, as high particle counts can lead to performance issues.
// Conceptual usage pattern
late ConfettiController _controller;
@override
void initState() {
_controller = ConfettiController(duration: const Duration(seconds: 2));
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ConfettiWidget(controller: _controller);
}