post_enrollment_app/lib/pages/helpers/android_download_helper.dart

37 lines
906 B
Dart

import 'dart:io';
import 'package:flutter/services.dart';
const MethodChannel _downloadsChannel = MethodChannel('nhance/downloads');
Future<int?> androidSdkInt() async {
if (!Platform.isAndroid) return null;
try {
final sdkInt = await _downloadsChannel.invokeMethod<int>('getSdkInt');
return sdkInt;
} catch (_) {
return null;
}
}
Future<String> savePdfToAndroidDownloads({
required String fileName,
required List<int> bytes,
}) async {
final savedPath = await _downloadsChannel.invokeMethod<String>(
'saveToDownloads',
{
'fileName': fileName,
'bytes': bytes,
},
);
if (savedPath == null || savedPath.isEmpty) {
throw const FileSystemException('Unable to save file to Downloads');
}
return savedPath;
}
Future<void> openAndroidDownloadedFile(String path) async {
await _downloadsChannel.invokeMethod<void>('openFile', {'path': path});
}