已经3天了,我试图用我的Flutter应用程序修复音频文件下载的问题。当我尝试下载音频文件时,请求保持"等待"状态。状态和完成,没有错误。
我做了很多研究,发现客户的contentLength
总是为0,但这没有帮助。
现在我试着让一个get请求与样本音频文件的网站,它不工作太。我已经通过邮差测试过了,它总是工作的。
我的函数:
Future<void> _download(String url, String filepath) async {
final response = await this.get("https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_700KB.mp3");// await this.get("$baseURL$url");
log("Try to get audio files: ${response.isOk}");
if (response.isOk) {
File file = File(filepath);
final raf = file.openSync(mode: FileMode.write);
response.bodyBytes.listen((value) {
raf.writeFromSync(value);
}, onDone: () {
log("closed $filepath");
raf.closeSync();
});
}
}
response.isOk
总是false
。
我使用GetConnect
从GetX包谁使用httpClient。
通过Dart devtools我从请求中获得:
https://prnt。Sc/1q3w33z
https://prnt.sc/1q3x9ot
所以我使用了另一个包:Dio,现在它可以工作了。