-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Description
I am trying to show two web pages on my custom view widget on flutter web app. I have two button for that. So in order to I am using IFrameElement to add my web page like this:
@override
// ignore: must_call_super
void didChangeDependencies() {
final IFrameElement iframeElement = IFrameElement();
iframeElement.height = MediaQuery.of(context).size.height.toString();
iframeElement.width = MediaQuery.of(context).size.width.toString();
iframeElement.src = widget.url;
iframeElement.style.border = 'none';
iframeElement.id = 'iframe';
// ignore:undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
'iframeElement',
(int viewId) => iframeElement,
);
_iframeWidget = HtmlElementView(
// key: UniqueKey(),
viewType: 'iframeElement',
);
}
@override
Widget build(BuildContext context) {
return SizedBox(
height: 600,
width: 600,
child: _iframeWidget,
);
}
A problem was here :
When i tried to use ui.platformViewRegistry. platformViewRegistry does not exist anymore
https://pasteboard.co/JyR1Sje9.png
So according some post i created
// UiFake.dart
// ignore: camel_case_types
class platformViewRegistry {
static registerViewFactory(String viewId, dynamic cb) {}
}
And i use in my custom view like this:
import 'package:iparsian_flutter/custom_widgets/ui_fake.dart'
if (dart.library.html) 'dart:ui' as ui;
After added ui.platformViewRegistry As you can see iframeElement.src = widget.url;, I pass web page url from it's constructor.
When i clicked on first button, first web page is opened and everything is ok, When i clicked on chrome back button and clicked on second button, first web page opened again !!!
While i passed other web page into my custom class.Seems first web page cached.
Is it possible to clear cached?Or remove IFrameElement ? And why IFrameElement not created again?
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 1.23.0-18.1.pre, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.50.1)
[✓] Connected device (2 available)
• No issues found!