I am trying to set the new URL(i.e an HTML string) which I am parsing every time the src changes. but with this code, I am able to show only the first src and it is not changing and showing the same src of output every time.
class IframeView extends StatefulWidget {
String url;
frameView(this.url);
@override
_IframeViewState createState() => _IframeViewState(url);
}
class _IframeViewState extends State<IframeView> {
String url;
_IframeViewState(this.url);
final html.IFrameElement _iframeElement = html.IFrameElement();
Widget _iframeWidget;
@override
void initState() {
_iframeElement.height = '500';
_iframeElement.width = '500';
_iframeElement.srcdoc = widget.url;
_iframeElement.style.border = 'none';
// print("src printing");
// print(_iframeElement.srcdoc);
// print("widget url");
// print(widget.url);
ui.platformViewRegistry.registerViewFactory('iframeElement', (int viewId) {
return _iframeElement;
});
_iframeWidget = HtmlElementView(
key: UniqueKey(),
viewType: 'iframeElement',
);
super.initState();
}
@override
void didUpdateWidget(IframeView oldWidget) {
super.didUpdateWidget(oldWidget);
print("from did update widget");
print(_iframeElement.srcdoc);
_iframeElement.srcdoc = widget.url;
}
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 50),
child: _iframeWidget,
);
}
}