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

52 Views Asked by At

I am using InAppWebView to directly download an octet-stream file in flutter whose URL starts with anchor tag - data:application/octet-stream;base64,iVBORw0K like this but i don't know how to implement this in webview android . Please help regarding this

Here is my code

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)
               );
            },
          ),

Please Help me regarding this ! Thanks

0

There are 0 best solutions below