Skip to content

Commit 9497bca

Browse files
committed
chore: Really remove audio file in example.
1 parent 2adf659 commit 9497bca

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

record/example/lib/main.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:io';
2+
13
import 'package:flutter/foundation.dart';
24
import 'package:flutter/material.dart';
35

@@ -14,37 +16,35 @@ class MyApp extends StatefulWidget {
1416
}
1517

1618
class _MyAppState extends State<MyApp> {
17-
bool showPlayer = false;
1819
String? audioPath;
1920

20-
@override
21-
void initState() {
22-
showPlayer = false;
23-
super.initState();
24-
}
25-
2621
@override
2722
Widget build(BuildContext context) {
2823
return MaterialApp(
2924
home: Scaffold(
3025
body: Center(
31-
child: showPlayer
26+
child: audioPath != null
3227
? Padding(
3328
padding: const EdgeInsets.symmetric(horizontal: 25),
3429
child: AudioPlayer(
3530
source: audioPath!,
3631
onDelete: () {
37-
setState(() => showPlayer = false);
32+
if (!kIsWeb) {
33+
try {
34+
File(audioPath!).deleteSync();
35+
} catch (_) {
36+
// Ignored
37+
}
38+
}
39+
40+
setState(() => audioPath = null);
3841
},
3942
),
4043
)
4144
: Recorder(
4245
onStop: (path) {
4346
if (kDebugMode) print('Recorded file path: $path');
44-
setState(() {
45-
audioPath = path;
46-
showPlayer = true;
47-
});
47+
setState(() => audioPath = path);
4848
},
4949
),
5050
),

0 commit comments

Comments
 (0)