fluttercommunity / fluttercommunity/flutter_downloader

iOS 14.5 download fails, error message: only success task can be opened

Open
#592 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
940
Forks
561
Avg merge
1h 18m
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.