Skip to content Skip to sidebar Skip to footer

How To Show Local Html Folder In Webview

I want to display a html folder in the webview, which includes CSS and javascript. Like this folder : javascript_button And this folder should be on the sdcard path of memory rath

Solution 1:

Use This Code using Webview_Flutter plugin in Scaffold:

  WebView(
            initialUrl: '',
            javascriptMode: JavascriptMode.unrestricted,
            onWebViewCreated: (WebViewController webViewController) {
              _webViewController = webViewController;
              _loadHtmlFromAssets();
            },
          ),

// function to load Assets files
//filePath in bellow code for ex.(String filePath = '/assests/files/abc1.html';)


_loadHtmlFromAssets() async {
    String fileHtmlContents = await rootBundle.loadString(filePath);
    _webViewController.loadUrl(Uri.dataFromString(fileHtmlContents,
        mimeType: 'text/html', encoding: Encoding.getByName('utf-8'))
        .toString());
  }

Post a Comment for "How To Show Local Html Folder In Webview"