Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.76k stars 815 forks source link

Add srcdoc, controller, and properties to iframe package #1349

Closed swiftymf closed 9 months ago

swiftymf commented 10 months ago

This branch allows developers to, in addition to 'src', pass in html that contains a 'srcdoc' property. 'src' is great for passing in a URL, but if someone wants to pass in HTML, etc., inside an iframe, then we need to use 'srcdoc'. This branch is broken into three commits since there are three separate features being introduced.

  1. Check is 'srcdoc' is sent in with the extensionContext attributes. If there is no 'srcdoc' we fallback to 'src'. This change doesn't break the current usage of the package and will not impact developers currently using it.
  2. Add an optional WebViewController to be passed in when constructing the IframeWidget. This would allow developers to have more control over what the WebViewController can do.
  3. Add IframeProperties class that has a width and height. Add an optional IframeProperties parameter to be passed in when constructing the IframeWidget. This would allow developers the control to set the width and height of the iframe.

Full disclosure: These changes solve an issue for me. I need to use 'srcdoc' to pass in HTML that also contains some JavaScript. The JavaScript has a method that can send a message back to the WebViewController through its .addJavaScriptChannel parameter. I use that to send the height of the iframe after it is loaded which I then pass back in through the IframeProperties. Without this, the iframe loads THEN the JavaScript run and the height of the iframe content changes but the Flutter widget remains too small to display the full content.