File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change 1+ import 'dart:io' ;
2+
13import 'package:flutter/foundation.dart' ;
24import 'package:flutter/material.dart' ;
35
@@ -14,37 +16,35 @@ class MyApp extends StatefulWidget {
1416}
1517
1618class _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 ),
You can’t perform that action at this time.
0 commit comments