fluttercommunity / fluttercommunity/flutter_downloader

Downloads sometimes fail with error message: `flutter: not found task corresponding to given task id`

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

Description

On both Android and iOS, downloads sometimes fail with this error message: `flutter: not found task corresponding to given task id`

I found that running `flutter clean` and rebuilding the app seems to make this disappear for a bit (download successful and file can be opened in relevant applications), but when I build the app again after changing something, the error returns. I've enabled Android cleartext traffic, to no avail.

Here's a minimal reproduction of my code:

```import 'dart:io';
import 'dart:isolate';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:path_provider/path_provider.dart';

void main(){
_initializeFlutterDownloader();
runApp(MyApp());
}

_initializeFlutterDownloader()async{
WidgetsFlutterBinding.ensureInitialized();
await FlutterDownloader.initialize();
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Downloader Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Downloader Example'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
ReceivePort _port = ReceivePort();

@override
void initState() {
super.initState();
_downloadListener();
}

static void downloadCallback(
String id, DownloadTaskStatus status, int progress) {
final SendPort send =
IsolateNameServer.lookupPortByName('downloader_send_port');
send.send([id, status, progress]);
}

_downloadListener() {
IsolateNameServer.registerPortWithName(
_port.sendPort, 'downloader_send_port');
_port.listen((dynamic data) {
String id = data[0];
DownloadTaskStatus status = data[1];
if (status.toString() == "DownloadTaskStatus(3)") {
FlutterDownloader.open(taskId: id);
}
});
FlutterDownloader.registerCallback(downloadCallback);
}

void _download() async {
String _localPath =
(await findLocalPath()) + Platform.pathSeparator + 'Example_Downloads';

final savedDir = Directory(_localPath);
bool hasExisted = await savedDir.exists();
if (!hasExisted) {
savedDir.create();
}
String _url =
"https://www.colonialkc.org/wp-content/uploads/2015/07/Placeholder.png";
final download = await FlutterDownloader.enqueue(
url: _url,
savedDir: _localPath,
showNotification: true,
openFileFromNotification: true,
);
}

Future findLocalPath() async {
final directory =
// (MyGlobals.platform == "android")
// ?
await getExternalStorageDirectory();
// : await getApplicationDocumentsDirectory();
return directory.path;
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _download,
child: Icon(Icons.file_download),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
```

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.