Skip to content

Commit 037429e

Browse files
committed
Support switching multiple iframes
1 parent 8d4d529 commit 037429e

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

lib/src/replaced_element.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,13 @@ class ImageContentElement extends ReplacedElement {
9090
}
9191
}
9292

93-
/// Create a webview controller and old src independent of [IframeContentElement]
94-
/// to make sure it doesn't reset when the html string is updated
95-
WebViewController controller;
96-
String oldUrl;
97-
9893
/// [IframeContentElement is a [ReplacedElement] with web content.
9994
class IframeContentElement extends ReplacedElement {
10095
final String src;
10196
final double width;
10297
final double height;
10398
final NavigationDelegate navigationDelegate;
99+
final GlobalKey key = GlobalKey();
104100

105101
IframeContentElement({
106102
String name,
@@ -115,18 +111,12 @@ class IframeContentElement extends ReplacedElement {
115111
@override
116112
Widget toWidget(RenderContext context) {
117113
final sandboxMode = attributes["sandbox"];
118-
if (oldUrl != null && src != oldUrl && controller != null) {
119-
controller.loadUrl(src);
120-
}
121-
oldUrl = src;
122114
return Container(
123115
width: width ?? (height ?? 150) * 2,
124116
height: height ?? (width ?? 300) / 2,
125117
child: WebView(
126118
initialUrl: src,
127-
onWebViewCreated: (WebViewController webController) {
128-
controller = webController;
129-
},
119+
key: key,
130120
javascriptMode: sandboxMode == null || sandboxMode == "allow-scripts"
131121
? JavascriptMode.unrestricted
132122
: JavascriptMode.disabled,

0 commit comments

Comments
 (0)