downloadFile method
Implementation
@override
Future<String> downloadFile(String remoteRelativePath,
{String? localRelativePath}) async {
try {
final appDir = await getApplicationDocumentsDirectory();
final localPath = localRelativePath ?? remoteRelativePath;
final fullLocalPath = path.join(appDir.path, localPath);
// Ensure the directory exists
await Directory(path.dirname(fullLocalPath)).create(recursive: true);
// Download the file
final ref = FirebaseStorage.instance.ref(remoteRelativePath);
final file = File(fullLocalPath);
await ref.writeToFile(file);
// Return the relative path
return localPath;
} catch (e) {
debugPrint('Error downloading file: $e');
rethrow;
}
}