-
Notifications
You must be signed in to change notification settings - Fork 73
/
confetti.dart
78 lines (67 loc) · 1.88 KB
/
confetti.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import 'package:flutter/material.dart';
import 'package:confetti/confetti.dart';
class MyConfetti extends StatefulWidget {
const MyConfetti({Key? key}) : super(key: key);
@override
State<MyConfetti> createState() => _MyConfettiState();
}
class _MyConfettiState extends State<MyConfetti> {
bool isPlaying = false;
final controller = ConfettiController();
@override
void initState() {
super.initState();
/// Listen to states: playing, stopped
controller.addListener(() {
setState(() {
isPlaying = controller.state == ConfettiControllerState.playing;
});
});
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.center,
children: [
Scaffold(
backgroundColor: Colors.black87,
appBar: AppBar(title: const Text('Confetti')),
body: Center(
child: ElevatedButton(
child: Text(isPlaying ? 'Stop 🥳' : 'Celebrate 🥳'),
onPressed: () {
if (isPlaying) {
controller.stop();
} else {
controller.play();
}
},
),
),
),
ConfettiWidget(
confettiController: controller,
shouldLoop: true,
// set direction
// blastDirection: -pi / 2, //up
// blastDirection: 0, //right
// blastDirection: pi / 2, //down
// blastDirection: pi, //left
/// all direction
blastDirectionality: BlastDirectionality.explosive,
/// set emission count
emissionFrequency: 0.50, // 0.0 -> 1.0
numberOfParticles: 20,
/// set intensity
minBlastForce: 10,
maxBlastForce: 100,
),
],
);
}
}