我正在尝试使用flutter从网站下载文件,我首先使用了evaluateJavaScript并在单击生成按钮之前更改了一些值,该按钮应该将适当的pdf文件下载到手机。
这是我的代码:
InAppWebView(
initialUrl: '...',
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true,
useOnDownloadStart: true,
javaScriptEnabled: true,
),
),
//javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (InAppWebViewController webViewController) {
_controller = webViewController;
},
onLoadStop: (_controller ,url) async {
await _loadData();
_controller.evaluateJavascript(source:
"console.log(document.getElementById('field-lastname').value = '${data[Field.name]}' );"
+"console.log(document.getElementById('generate-btn').click());"
);
},
onDownloadStart:(_controller,url) async{
print("onDownloadStart $url");
final taskId = await FlutterDownloader.enqueue(
url: url,
savedDir: (await getExternalStorageDirectory()).path,
showNotification: true, // show download progress in status bar (for Android)
openFileFromNotification: true,);
},
),
Run Code Online (Sandbox Code Playgroud)
打印出来的网址是这样的
onDownloadStart blob:https://example.com/a2a5316c-9290-4da7-8a2a-9f899861046a
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?