skip to Main Content

I’m trying to make a html ad widget using html package, but the widget just occupy space, doesn’t display layout.

Widget _adWIdget() {
    return Html(data: """
    <iframe src=adUrl width="100%" height="44" frameborder="0" scrolling="no" referrerpolicy="unsafe-url"></iframe>
    """);
  }

I think it’s because I didn’t setup a layout showing, how can I show the html layout?

2

Answers


  1. Chosen as BEST ANSWER

    I solved it, when using iframe, you should use not only html but also the external package html_iframe.(you can install 'flutter pub add flutter_html_iframe')

    The external package includes the following.

    • flutter_html_all
    • flutter_html_audio
    • flutter_html_iframe
    • flutter_html_math
    • flutter_html_svg
    • flutter_html_table
    • flutter_html_video

    and you can use the following code.

    Widget _adWIdget() {
      return Html(
        data: """
          <iframe src=adUrl width="100%" height="44" frameborder="0" scrolling="no" referrerpolicy="unsafe-url"></iframe>
          """,
        extensions: [
          IframeHtmlExtension(),
        ],
      );
    }
    

  2. You will need to use flutter_html package to achieve your requirement.

    Widget _adWidget() {
        String adUrl =
            "your-ad-url"; // I created a sample html page on codepen for result. You can provide your ad-url.
    
        return Html(
          data: '''
          <iframe src="$adUrl" width="100%" height="44" frameborder="0" scrolling="no" referrerpolicy="unsafe-url"></iframe>
          ''',
        );
    

    Result:

    Result

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search