Skip to content

[web] IFrameElement will not get disposed on navigating back #69813

@tazik561

Description

@tazik561

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!

Metadata

Metadata

Assignees

Labels

a: qualityA truly polished experienceassigned for triageissue is assigned to a domain expert for further triageengineflutter/engine related. See also e: labels.found in release: 1.23Found to occur in 1.23found in release: 1.24Found to occur in 1.24has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions