Skip to content

Conversation

tneotia
Copy link
Contributor

@tneotia tneotia commented Feb 11, 2021

Fixes #337

import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_html/image_render.dart';
import 'package:flutter_html/style.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.deepPurple,
      ),
      home: new MyHomePage(title: 'flutter_html Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

String htmlData = """
      <h3>IFrame support:</h3>
              <iframe src="https://bing.com"></iframe>
""";

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        title: Text('flutter_html Example'),
        centerTitle: true,
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            if (htmlData.contains("bing")) {
              htmlData = """<h3>IFrame support:</h3>
              <iframe src="https://google.com"></iframe>
              """;
            } else {
              htmlData = """<h3>IFrame support:</h3>
              <iframe src="https://bing.com"></iframe>
              """;
            }
          });
        },
        child: Icon(Icons.change_history),
      ),
      body: SingleChildScrollView(
        child: Html(
          data: htmlData,
        ),
      ),
    );
  }
}

}
}

/// Create a webview controller and old src independent of [IframeContentElement]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 What if you have two iframes? Does this work (independently)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah that's something very important that I overlooked. I'm going to mark this as a draft and come back to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erickok turns out you only need to assign a key to make it work right, as @The-Redhat commented on #337. Now it should work independently!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait but now the whole Html widget is controlled by the single key... What is the impact of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only assigned the key to the WebView. Each WebView will get a different key when a new IframeContentElement class is created.

@tneotia tneotia marked this pull request as draft February 11, 2021 22:33
@tneotia tneotia marked this pull request as ready for review February 11, 2021 23:37
final double width;
final double height;
final NavigationDelegate navigationDelegate;
final GlobalKey key = GlobalKey();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have to be a global key? Pretty sure this can be an ObjectKey.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure it could be any sort of Key. Is there an advantage to using one type over another?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for efficiency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erickok changed the key to UniqueKey, its essentially the same as ObjectKey but doesn't require an Object argument.

@erickok erickok merged commit 226e2d3 into Sub6Resources:master Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iframe does not change when the html string passed to data changes

2 participants