downloadFile method

  1. @override
Future<String> downloadFile(
  1. String remoteRelativePath, {
  2. String? localRelativePath,
})
override

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;
  }
}