How to render partial content of a website in Flutter?

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: 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

1 answer

  • answered 2020-02-13 00:41 Maks

    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(
            mimeType: 'text/html',
            encoding: Encoding.getByName('utf-8')

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