[英]Flutter downloader fails everytime. Sometimes there is a progress of 97
I try to download a image from a website with the help of flutter_downloader.我尝试在 flutter_downloader 的帮助下从网站下载图像。 The download fails everytime immediately after starting.
每次启动后立即下载失败。 I dont know why.
我不知道为什么。
I tried to keep the code as small as possible so somethings are missing but they arent important for my problem This is my code:我试图使代码尽可能小,因此缺少一些东西,但它们对我的问题并不重要这是我的代码:
int progress = 0;
ReceivePort receivePort = ReceivePort();
@override
void initState() {
IsolateNameServer.registerPortWithName(receivePort.sendPort, "downloadingvideo");
receivePort.listen((dynamic data) {
String id = data[0];
DownloadTaskStatus status =
data[1]; int progress = data[2];
print("Id: ${id}, Status: ${status}, Progress: ${progress},");
});
FlutterDownloader.registerCallback(downloadCallback);
// TODO: implement initState
super.initState();
}
@override
void dispose() {
IsolateNameServer.removePortNameMapping("downloadingvideo");
super.dispose();
}
static downloadCallback(String id, DownloadTaskStatus status, int progress){
final SendPort sendPort = IsolateNameServer.lookupPortByName("downloadingvideo")!;
sendPort.send([id, status, progress]);
}
void _download(String url, String title) async {
final status = await Permission.storage.request();
if(status.isGranted){
final externalDir = await getExternalStorageDirectory();
final id = await FlutterDownloader.enqueue(
url: url, savedDir: externalDir!.path,
fileName: title,
showNotification: true,
openFileFromNotification: true,
saveInPublicStorage: true,
);
} else{
print("Permission denied!");
}
}
@override
Widget build(BuildContext context) {
return Center(
child: Container(
child: FlatButton(
onPressed: () {
_download("https://www.bergfreunde.de/out/pictures/promo/bs-teaser_y22_1.jpg", "name.png");
},
child: Text("Download"),
),
)
);
}
}
This is the new error I get:这是我得到的新错误:
W/System.err(21506): java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.example.musicanywhere_app.flutter_downloader.provider
W/System.err(21506): at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:662)
W/System.err(21506): at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:635)
W/System.err(21506): at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:441)
W/System.err(21506): at vn.hunghd.flutterdownloader.IntentUtils.buildIntent(IntentUtils.java:23)
W/System.err(21506): at vn.hunghd.flutterdownloader.IntentUtils.validatedFileIntent(IntentUtils.java:35)
W/System.err(21506): at vn.hunghd.flutterdownloader.DownloadWorker.downloadFile(DownloadWorker.java:441)
W/System.err(21506): at vn.hunghd.flutterdownloader.DownloadWorker.doWork(DownloadWorker.java:235)
W/System.err(21506): at androidx.work.Worker$1.run(Worker.java:86)
W/System.err(21506): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err(21506): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err(21506): at java.lang.Thread.run(Thread.java:923)
I/WM-WorkerWrapper(21506): Worker result FAILURE for Work [ id=54727eb0-aa34-4bc5-94fd-558debd43804, tags={ flutter_download_task, vn.hunghd.flutterdownloader.DownloadWorker } ]
Thanks for your help.谢谢你的帮助。
The error in your stack trace reads:堆栈跟踪中的错误为:
java.net.MalformedURLException: no protocol: musikschulemarsulm.de/static/css/marsheader_white_smal.png
java.net.MalformedURLException:无协议:musikschulemarsulm.de/static/css/marsheader_white_smal.png
And in your code you have:在你的代码中你有:
_download("musikschulemarsulm.de/static/css/marsheader_white_smal.png", "name.png");
There needs to be a protocol for the url you are giving for the image.您为图像提供的 url 需要有一个协议。
You are either missing http or https from the url.您从 url 中缺少 http 或 https。
_download("https://musikschulemarsulm.de/static/css/marsheader_white_smal.png", "name.png");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.