Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - How to download files in WebView?

I am using flutter_webview_plugin: ^0.3.8 but I have the same problem with webview_flutter: ^0.3.13.

In webview, I want to make use of a website which triggers a file download on successful completion of a captcha. However, I complete the captcha and nothing happens, no download.

Is there something in Flutter like a webview download listener ("webview.setDownloadListener")? I only need this for Android.

If not, is there a way of downloading files from a webview in Flutter?

like image 250
Code Poet Avatar asked Sep 14 '19 17:09

Code Poet


People also ask

How do I download from flutter WebView?

You can use my plugin flutter_inappwebview, which is a Flutter plugin that allows you to add inline WebViews or open an in-app browser window and has a lot of events, methods, and options to control WebViews. It can recognize downloadable files in both Android (using setDownloadListener ) and iOS platforms!

How do I enable downloads in flutter WebView?

It can recognize downloadable files in both Android (using setDownloadListener ) and iOS platforms! To be able to recognize downloadable files, you need to set the useOnDownloadStart: true option, and then you can listen the onDownloadStart event! Then, you need to ask permission using the permission_handler plugin.

How do I download local files on flutter?

To download the file and store it in the download folder using flutter we need to use files_utils and path_provider Plugin in our App. This will provide us to store files into our sdcard/downloads folder and then we can use flutter_downloader OR dio plugin to download file and then we can save it in our specific path.


1 Answers

just add this code to your AndroidManifest.xml

   <provider
            android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider"
            android:authorities="${applicationId}.flutter_downloader.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
    </provider>

and add this code to your AndroidManifest.xml

it works to me

like image 191
Rilas agung pambudi Avatar answered Sep 20 '22 20:09

Rilas agung pambudi