flutter_downloader
flutter_downloader copied to clipboard
iOS 14.5 download fails, error message: only success task can be opened
This is my code:
PDFDocument document; ReceivePort _receivePort = ReceivePort(); double progress = 0; static const String _named = 'downloading';
static void downloadCallback( String id, DownloadTaskStatus status, int progress) { SendPort port = IsolateNameServer.lookupPortByName('$_named'); port.send(progress); }
@override void initState() { super.initState(); loading = true; IsolateNameServer.registerPortWithName(_receivePort.sendPort, '$_named');
_receivePort.listen((message) {
print(message);
setState(() {
progress = message + .0;
});
});
FlutterDownloader.registerCallback(downloadCallback);
this.getPdf();
}
@override void dispose() { super.dispose(); IsolateNameServer.removePortNameMapping('$_named'); this._receivePort.close(); FlutterDownloader.cancelAll(); }
void getPdf() { PDFDocument.fromURL( '${this.widget.url}', ).then((value) { setState(() { this.document = value; loading = false; }); }).catchError((error) { setState(() { this.loading = false; this.error = error.toString(); }); }); }
And the button: GestureDetector( onTap: () async { _loading(); ApiClient apiClient = getIt.getItInstance<ApiClient>(); await apiClient.downloadFile(this.widget.url); Navigator.pop(context); },
This is the downloadFile function: dynamic downloadFile(String path) async { if (Platform.isAndroid) { var status = await Permission.storage.status;
if (status != PermissionStatus.granted) {
await Permission.storage.request();
} else {
print('No permission');
}
}
Directory appDocDir = Platform.isAndroid
? await getExternalStorageDirectory()
: await getApplicationDocumentsDirectory();
String pathToSave = Platform.isAndroid
? '${appDocDir.path.split('/Android/')[0]}/Download/'
: '${appDocDir.path}';
List pathSplit = path.split('.');
final taskId = await FlutterDownloader.enqueue(
url: '$path',
savedDir: '$pathToSave',
fileName: '${Uuid().v4()}.pdf',
showNotification: true,
openFileFromNotification: true,
);
await FlutterDownloader.open(taskId: taskId);
return taskId;
}
Hi there, Any update on this ? I am also getting the same error
flutter_downloader: ^1.7.1 Flutter version 2.10.4
You can't open file from a download task which is not successful.