如何在 Flutter WebView android 中直接下载锚点标签文件?

How to directly download anchor tag file in Flutter WebView android?

提问人:Raghav Sood 提问时间:11/17/2023 更新时间:11/17/2023 访问量:11

问:

我正在使用 InAppWebView 在 flutter 中直接下载一个 octet-stream 文件,其 URL 以 anchor 标签开头 - 像这样,但我不知道如何在 webview android 中实现这一点。请对此提供帮助data:application/octet-stream;base64,iVBORw0K

这是我的代码

InAppWebView(
            androidOnPermissionRequest: (InAppWebViewController controller, String origin, List<String> resources) async {
              return PermissionRequestResponse(
                resources: resources,
                action: PermissionRequestResponseAction.GRANT
              );
            },
            shouldOverrideUrlLoading: (controller, navigationAction) async {
              final uri = navigationAction.request.url!;
              print(uri);
              return NavigationActionPolicy.ALLOW;
            },
            onPageCommitVisible: (con,uri){
              print("url ${uri.toString()}");
            },
            initialUrlRequest: URLRequest(
              url: Uri.parse(digitalCardUrl),
            ),
            initialOptions: InAppWebViewGroupOptions(
                crossPlatform: InAppWebViewOptions(
                  useOnDownloadStart: true
                )
            ),
            onWebViewCreated: (InAppWebViewController controller) {
              _webViewController = controller;
            },
            onLoadStart: (InAppWebViewController controller, Uri? url) {
              setState(() {
                isLoading = true;
              });
            },
            onLoadStop: (InAppWebViewController controller, Uri? url) async {
              setState(() {
                isLoading = false;
              });
            },
            onProgressChanged: (InAppWebViewController controller, int progress) {
              setState(() {
                this.progress = progress / 100;
              });
            },
            onDownloadStart: (InAppWebViewController controller, Uri url) async {
              print("onDownloadStart $url");
               final taskId = await FlutterDownloader.enqueue(
                   url: url.toString(),
                   savedDir: (await getExternalStorageDirectory())!.path,
               showNotification: true, // show download progress in status bar (for Android)
               openFileFromNotification: true, // click on notification to open downloaded file (for Android)
               );
            },
          ),

请帮帮我!谢谢

flutter-dependencies 飞镖-html

评论


答: 暂无答案