- Creating a folder
static Future<String> saveVoiceDirectory(String url) async { requestPermission(); final filepath = await getApplicationDocumentsDirectory(); var file = Directory(filepath.path + "/" + url); try { bool exists = await file.exists(); if(! exists) { await file.create();print("Created successfully"); } else { print("Pre-existing"); } } catch (e) { print(e); } return file.path.toString(); } Copy the code
- GetApplicationDocumentsDirector need to pour into path_provider: path_provider: ^ 1.6.10
-
Create a file
saveVoiceDirectory("flutter").then((value) { File file = new File( value + "/" + "${DateTime.now().millisecondsSinceEpoch}.pcm"); if (!file.existsSync()) { file.createSync(); } }); Copy the code
-
File permissions
static Future requestPermission() async { if (await Permission.contacts.request().isGranted) { // Either the permission was already granted before or the user just granted it. } // You can request multiple permissions at once. Map<Permission, PermissionStatus> statuses = await [ Permission.storage, ].request(); print(statuses[Permission.storage]); } Copy the code
- Pour into the permission library: permission_handler: ^5.0.1+1