'Getting write access to a directory path in flutter API 30 and above
I want to know how to get write access to a directory path in flutter on API 30 and above. Currently, I cannot find a working complete solution to it anywhere on the internet.
And it would be very grateful if anyone could answer this completely in a detailed way or provide a working sample project.
Solution 1:[1]
Note: I know this is not accurately an answer to my question that's why not marked as an answer but this could be useful for those who wanted the "write access" for saving a file in a user-defined location with the native save dialog.
Add flutter_file_dialog plugin in pubspec.yaml. (Version 2.3.0 used in this answer)
Create a function like this.
Future<String?> saveFileInUserDescribedLocation() async {
//Create parameters for save file dialog
//Saving a file through Uint8List data
final params = SaveFileDialogParams(
mimeTypesFilter: ["application/pdf"],
data: Uint8List.fromList(bytes),
fileName: 'Test.pdf');
//You can also use a source file path to save a file through its path like this
//final params = SaveFileDialogParams(
// sourceFilePath: tempPdfPath, mimeTypesFilter: ["application/pdf"]);
//Now provide parameters and save the file.
//It will return the file path chosen by the user to save the file after saving the file.
final filePath = await FlutterFileDialog.saveFile(params: params);
debugPrint("Save filePath: $filePath");
return filePath;
}
- Then execute the saveFileInUserDescribedLocation() function. It will provide a native dialog to the user asking the user to choose a location to save and then saves the file.
ElevatedButton(
onPressed: () { await saveFileInUserDescribedLocation(); },
child: const Text("Save File")
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Deepanshu |
