Skip to content

Commit e3d05a7

Browse files
committed
Fix leaking tickers
1 parent a199c2e commit e3d05a7

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

lib/src/widgets/flow_shader.dart

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ class _FlowShaderState extends State<FlowShader>
2626
late Animation animation2;
2727
late Animation animation3;
2828

29+
@override
30+
void dispose() {
31+
controller.dispose();
32+
super.dispose();
33+
}
34+
2935
@override
3036
void initState() {
3137
super.initState();

lib/src/widgets/record_button.dart

+11-5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class _RecordButtonState extends State<RecordButton> {
7777
void dispose() {
7878
record.dispose();
7979
timer?.cancel();
80+
timer = null;
8081
super.dispose();
8182
}
8283

@@ -171,16 +172,17 @@ class _RecordButtonState extends State<RecordButton> {
171172
behavior: HitTestBehavior.opaque,
172173
onTap: () async {
173174
var filePath = await Record().stop();
175+
timer?.cancel();
176+
timer = null;
177+
startTime = null;
178+
recordDuration = "00:00";
174179
AudioState.files.add(filePath!);
175180
Globals.audioListKey.currentState!
176181
.insertItem(AudioState.files.length - 1);
177182
debugPrint(filePath);
178183
setState(() {
179184
isLocked = false;
180185
});
181-
startTime = null;
182-
recordDuration = "00:00";
183-
timer?.cancel();
184186
},
185187
child: Row(
186188
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -231,9 +233,11 @@ class _RecordButtonState extends State<RecordButton> {
231233
widget.controller.reverse();
232234

233235
if (isCancelled(details.localPosition)) {
236+
timer?.cancel();
237+
timer = null;
234238
startTime = null;
235239
recordDuration = "00:00";
236-
timer?.cancel();
240+
237241
debugPrint("Cancelled recording");
238242
var filePath = await record.stop();
239243
debugPrint(filePath);
@@ -245,9 +249,11 @@ class _RecordButtonState extends State<RecordButton> {
245249
isLocked = true;
246250
});
247251
} else {
252+
timer?.cancel();
253+
timer = null;
248254
startTime = null;
249255
recordDuration = "00:00";
250-
timer?.cancel();
256+
251257
var filePath = await Record().stop();
252258
AudioState.files.add(filePath!);
253259
Globals.audioListKey.currentState!

0 commit comments

Comments
 (0)