diff --git a/lib/api_service.dart b/lib/api_service.dart index 40a9f6e..3ad7da9 100644 --- a/lib/api_service.dart +++ b/lib/api_service.dart @@ -5,6 +5,7 @@ import 'dart:ui_web' as ui; import 'dart:html' as html; import 'augment.dart'; import 'dart:js' as js; +// import 'package:flutter_web_plugins/flutter_web_plugins.dart'; class MailAddress { final String? name; @@ -341,47 +342,59 @@ class EmailView extends StatefulWidget { class _EmailViewState extends State { late Key iframeKey; + late String currentContent; + late String viewTypeId; @override void initState() { super.initState(); - print(widget.id); - iframeKey = Key("iframe-${widget.id}"); - ui.platformViewRegistry.registerViewFactory( - // 'html-view33' - iframeKey.toString(), - (int viewId) => html.IFrameElement() - ..width = '100%' - ..height = '100%' - ..srcdoc = widget.emailContent - ..style.border = 'none', - // ..style.width = '100%', - // ..style.height = '100%' - ); + String currentContent = widget.emailContent; + viewTypeId = "iframe-${DateTime.now().millisecondsSinceEpoch}"; + _registerViewFactory(currentContent); + } + + void _registerViewFactory(String currentContent) { + setState(() { + viewTypeId = 'iframe-${DateTime.now().millisecondsSinceEpoch}'; + ui.platformViewRegistry.registerViewFactory( + viewTypeId, + (int viewId) => html.IFrameElement() + ..width = '100%' + ..height = '100%' + ..srcdoc = currentContent + ..style.border = 'none'); + }); } @override Widget build(BuildContext context) { - void _handleNumbering() { - // Check if the iframe content window is accessible - try { - js.context.callMethod('applyNumberingVisibility'); - } catch (e) { - print('Error accessing iframe method: $e'); - // Optionally, use postMessage for cross-origin communication - // js.context['iframeElement'].contentWindow.postMessage(jsify({'action': 'toggleNumbering'}), '*'); - } - } - - - return Scaffold( appBar: AppBar( title: Text(widget.name), ), body: Column( children: [ - EmailToolbar(onButtonPressed: _handleNumbering), + EmailToolbar( + onButtonPressed: () { + _registerViewFactory(r""" +

Welcome to My Website

+

This is a simple HTML page.

+

What is HTML?

+

HTML (HyperText Markup Language) is the most basic building block of the Web. It defines the meaning and structure of web content. Other technologies besides HTML are generally used to describe a web page's appearance/presentation (CSS) or functionality/behavior (JavaScript).

+

Here's a simple list:

+ +

Copyright © 2023

+ """); + print("change"); + // widget.emailContent = r" + +// " + }, + ), Row( // title of email children: [ @@ -420,9 +433,8 @@ class _EmailViewState extends State { Expanded( child: HtmlElementView( - key: iframeKey, - viewType: iframeKey.toString(), - // 'html-view33', + key: UniqueKey(), + viewType: viewTypeId, ), ), ], diff --git a/lib/augment.dart b/lib/augment.dart index 5091d29..cb0b93c 100644 --- a/lib/augment.dart +++ b/lib/augment.dart @@ -23,6 +23,11 @@ class EmailToolbar extends StatelessWidget { onPressed: onButtonPressed, child: Text('Reload'), ), + Spacer(), + ElevatedButton( + onPressed: onButtonPressed, + child: Text('Options'), + ) ], );