-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.dart
169 lines (155 loc) · 5.74 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:heart_overlay/heart_overlay.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData.dark(useMaterial3: true),
home: const HeartOverlayTestWidget(),
);
}
}
class HeartOverlayTestWidget extends StatefulWidget {
const HeartOverlayTestWidget({
super.key,
});
@override
State<HeartOverlayTestWidget> createState() => _HeartOverlayTestWidgetState();
}
class _HeartOverlayTestWidgetState extends State<HeartOverlayTestWidget> {
late HeartOverlayController heartOverlayController;
@override
void initState() {
super.initState();
heartOverlayController = HeartOverlayController();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black45,
appBar: AppBar(
title: const Text('Heart Overlay'),
centerTitle: true,
backgroundColor: Colors.cyan,
),
body: Column(
children: [
Expanded(
child: HeartOverlay(
controller: heartOverlayController,
duration: const Duration(seconds: 5),
backgroundColor: Colors.black,
tapDownType: TapDownType.single,
// verticalOffset: 20,
// horizontalOffset: -100,
enableGestures: true,
cacheExtent: 30,
splashAnimationDetails: const SplashAnimationDetails(
enableSplash: true,
animationDuration: Duration(seconds: 3),
),
icon: const Icon(
Icons.favorite,
color: Colors.redAccent,
size: 100,
),
onPressed: (numberOfHearts) {
// Do something with the number of hearts or do something whenever the icon appears
},
child: Center(
child: ElevatedButton(
child: const Text('h'),
onPressed: () {
debugPrint(
''' The following condition applies to all children that receive tap events within the HeartOverlay's `child`
If enablegestures is true
- Tap events in the child only work if the `tapdowntype` is double else they might not
- And when tapdowntype is set to double and the child's callback works well,
it might feel a bit delayed or slow but that's not performance issue at all but
rather flutter's gesturedetector widget having a 300ms delay waiting on the double
tapdown before letting other callbacks work, you can
visit the issue https://github.com/flutter/flutter/issues/106170
If enableGestures is false
- Tap events within the child will work as normal''',
);
},
),
),
),
),
Padding(
padding: const EdgeInsets.all(50.0),
child: ElevatedButton(
onPressed: () {
// Get the center offset
// Offset centerOffset =
// heartOverlayController.getCenterScreenOffset(context);
double iconSize = heartOverlayController.getSize() * 2;
double height = heartOverlayController.getHeight() ??
MediaQuery.of(context).size.height;
double width = heartOverlayController.getWidth() ??
MediaQuery.of(context).size.width;
Offset offset = Offset(
// DX
(Random().nextDouble() * width).clamp(
iconSize,
width - iconSize,
),
// DY
(Random().nextDouble() * height).clamp(
iconSize,
height - iconSize - 100,
), // - 100 is for the button padding
);
// offset += centerOffset; // You can add offsets
// Show the icon at the provided offset
heartOverlayController.showIcon(
offset: offset,
);
// Changes to the emoji on the second click
heartOverlayController.changeIcon(
icon: const Text('👀'), // Required
size: 200, // Not required
horizontalOffset: 10, // Not required
verticalOffset: 30, // Not required
);
},
child: const Text('Show Icon'),
),
)
// Expanded(
// child: HeartOverlay(
// duration: const Duration(seconds: 2),
// backgroundColor: Colors.white10,
// tapDownType: TapDownType.single,
// icon: const Text('✌️'),
// // Splash would not work because the [icon] provided is not of type [Icon]
// splashAnimationDetails: const SplashAnimationDetails(
// enableSplash: true,
// ),
// size: 60,
// // Sometimes it might be nesessary to add vertical and horizontal offset
// verticalOffset: 20,
// horizontalOffset: -10,
// onPressed: (numberOfHearts) {
// // Do something with the number of hearts or do something whenever the icon appears
// },
// child: Center(
// child: ElevatedButton(
// onPressed: () {},
// child: const Text('Tap here'),
// ),
// ),
// ),
// ),
],
),
);
}
}