1

I am new to Flutter and I would like to render a partial content from a website in my Flutter application. Imagine this as an example: I want to render the main content of this website: https://flutter.dev/. I could obtain this content by executing the javascript command: document.getElementsByClassName("container")[0] .

What do I have to do to display this content in an WebView inside my Flutter application?

Thank you

André Azevedo
  • 227
  • 1
  • 4
  • 11

1 Answers1

0

This answer demonstrates how to pass html content to a Webview plugin in Flutter. In your case you dont need to read from a file as in that answer, just pass in the String that you obtain from whatever means you need to use.

The relevant part of that answers code for you is:

 String fileText = await rootBundle.loadString('assets/help.html');
    _controller.loadUrl( Uri.dataFromString(
        fileText,
        mimeType: 'text/html',
        encoding: Encoding.getByName('utf-8')
    ).toString());

where in your case the fileText String is the html content that you got from somewhere.

Maks
  • 7,562
  • 6
  • 43
  • 65