getAppDocumentsDirectoryPath method
Implementation
@override
Future<String> getAppDocumentsDirectoryPath([String? pathSufix]) async {
try {
Directory? directory;
// For Android, use getExternalStorageDirectory.
// For iOS, use getApplicationDocumentsDirectory as iOS doesn't support external storage.
if (Platform.isAndroid) {
directory = await getExternalStorageDirectory();
} else if (Platform.isIOS) {
directory = await getApplicationDocumentsDirectory();
}
// You can use your app's subdirectory within the external storage directory.
final String path =
'${directory?.path}${pathSufix.isNotNullOrEmpty ? '/${pathSufix}' : ''}';
// Creating the directory if it doesn't exist
final myDir = Directory(path);
if (!await myDir.exists()) {
await myDir.create(recursive: true);
}
return path;
} catch (e) {
debugPrint('FileService > getDownloadsFolderPath: ${e.toString()}');
}
return '';
}