savePdfFile static method
Implementation
static Future<String?> savePdfFile(String title, List<int> bytes) async {
String ext = "pdf";
Future<String?> fileSaveTask;
title = "$title-${DateFormat("dd-MMM-yyyy-HHmmss").format(DateTime.now())}";
if (GetPlatform.isAndroid || GetPlatform.isIOS) {
fileSaveTask = FileSaver.instance.saveAs(
name: "$title.$ext",
bytes: Uint8List.fromList(bytes),
ext: ext,
mimeType: MimeType.pdf,
);
} else {
fileSaveTask = FileSaver.instance.saveFile(
name: title,
bytes: Uint8List.fromList(bytes),
ext: ext,
mimeType: MimeType.pdf,
);
}
final result = await fileSaveTask;
if (kDebugMode) {
print(result ?? "Unable to save file");
}
if (result == null) {
return null;
}
var filePath = File(result).absolute.path;
return filePath;
}