Webview render issue on iOS [Testflight]

Viewed 139

I'm trying to render a webview in my flutter project.
It's working perfectly for Android in debug and release modes and on iOS in debug mode as well.
However if I upload a build to Testflight, it does not work for some reason.
I've been working with the same code from the past few months and not had an issue with Flutter v1.

I'm attaching a code snippet below. Any help is appreciated.

Snippet:

return Container(
  width: size.width,
  height: size.height,
  child: WebView(
    key: UniqueKey(),
    initialUrl: renderHTML(width, content!),
    javascriptMode: JavascriptMode.unrestricted,
    javascriptChannels: <JavascriptChannel>[
      JavascriptChannel(
          name: 'GetImgSrc',
          onMessageReceived: (JavascriptMessage msg) {
            print('Stef Method Channel ${msg.message}');
            Navigator.of(context)
                .pushNamed(PhotoViewer.route, arguments: msg.message);
          }),
    ].toSet(),
    navigationDelegate: (request) => NewsArticleController()
        .navigationDelegate(request, content!, width),
  ),
);

renderHtml(width, content) {
    return Uri.dataFromString(body, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString();
}

Html Snippet:

String body = '''
    <html>

    <head>

        <meta name='viewport' content='initial-scale = 1.0, width=device-width'/>
        <style>
            html {
                width: ${width}px;
            }
            body {
                margin-left: 8px;
                margin-right: 8px;
                margin-top: 0px;
                margin-bottom: 0px;
                background-color: #F6F6F6;
            }

            em {
                font-style: italic;
            }

            .title {
                padding: 0 20px;
                font-family: Georgia,Times,Times New Roman,serif;
                font-size: 20px;
                font-weight: 600;
                letter-spacing: 1px;
                line-height: 32px;
                color:#3D3D3D;
            }

            .meta-desc {
                margin: 8px 0;
                font-size: 16px;
                text-align: left;
                color: #000000;
                font-family: Georgia,Times,Times New Roman,serif;
                font-weight: 400;
                line-height: 24px;
                letter-spacing: 1px;

            }

            .meta-data {
                padding: 12px 0 8px 20px;
                color:#818181;
                font-size: 12px;
                line-height: 20px;
                font-family: Georgia,Times,Times New Roman,serif;
            }

            .hero-img img {
                margin-left: -8px;
                width: ${double.parse(width)}px;
                height: auto;
            }
            
            .body-content {
              padding: 0 20px;
            }
            
            .body-content div, .body-content p, .body-content span {
                padding: 0 !important;
                margin-bottom: 15px !important;
                font-size: 20px;
                text-align: left;
                color: #000000;
                font-family: Georgia,Times,Times New Roman,serif;
                font-weight: 400;
                line-height: 31px;
            }

            .body-content img {
                width: 100%;
                height: auto;
                margin: auto;
            }

            a {
                color: #F50057;
                text-decoration: none;
                font-weight: bold;
            }

            .yt-iframe {
                width: ${double.parse(width) - 16}px;
                min-height: 200px;
            }

            iframe.instagram-media {
                margin: 0 auto 10px !important;
                /* width: ${double.parse(width) - 16}px !important; */
            }

            iframe {
                margin: 0 8px 10px -8px !important;
                width: 100% !important;
            }
        </style>
    </head>

    <body>
    <div class="hero-img cls-image">
      <img src="${content.images?.url}">
    </div>
    <div style="text-align: end; padding: 16px 20px 8px 0; font-size:12px; color:#818181;">${content.postDateStr}</div>
    <div class="title">
        ${content.title}
    </div>
    <!--<div class="meta-desc">
        ${content.metaTagDescription}
    </div>-->
    <div class="meta-data">
        By <span>${content.user}</span>
    </div>
    <div class="body-content">
        $body
    </div>
    </body>
    <script>
        var elements = document.getElementsByClassName("instagram-media");
        setTimeout(function(){
            for (var i = 0; i < elements.length; i++) {
                elements[i].style.width=('0px');
                console.log('initial width: ' + elements[i].style.width);
                elements[i].style.width=('${double.parse(width) - 16}px');
                console.log('final width: ' + elements[i].style.width);
            }
            console.log(elements);
        }, 1000);

        var images = document.getElementsByClassName("cls-image");

        var myFunction = function(event) {
            GetImgSrc.postMessage(event.target.src);
        };

        for (var i = 0; i < images.length; i++) {
            images[i].addEventListener('click', myFunction, false);
        }
    </script>
    </html>
    ''';

Flutter version: Channel stable, 2.2.3, on macOS 11.4 20F71 darwin-x64, locale en-US
webview_flutter version: 2.0.9

1 Answers
Related