Downloads sometimes fail with error message: `flutter: not found task corresponding to given task id`
See original GitHub issueOn 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: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<MyHomePage> {
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<String> 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: <Widget>[
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _download,
child: Icon(Icons.file_download),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Why do my downloads fail sometimes using flutter_downloader?
On both Android and iOS, downloads sometimes fail with this error message: flutter: not found task corresponding to given task id .
Read more >Upgrading your build from Gradle 6.x to the latest
Try to run the project and debug any errors using the Troubleshooting Guide. Upgrading from 6.8. Changes in the IDE integration. Changes in...
Read more >A Plugin for Creating and Managing Download Tasks - Morioh
Flutter Downloader. A plugin for creating and managing download tasks. Supports iOS and Android. This plugin is based on WorkManager in Android and ......
Read more >flutter_downloader 1.6.1 | Flutter Package - Pub.dev
Flutter Downloader # ... A plugin for creating and managing download tasks. Supports iOS and Android. This plugin is based on WorkManager in...
Read more >Firebase Apple SDK Release Notes - Google
Added notification support for iOS 16 simulators on Xcode 14. ... Fixed the previous CocoaPods release incorrectly missing the RemoteConfigProperty feature ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have this same problem on iOS simulator. Thank you LaxmikanthMadhyastha for the Future.delayed fix - this seems to solve the problem for me. However, it’s a bit of a hack, and it would be nice if this could be solved in the package 😃
It appears that the tasks won’t run after I performed hot restart. After each build, everything works fine, but once I hot restart, none of the tasks would run.