2 Commits 79c19abbc9 ... 47f24fe849

Autore SHA1 Messaggio Data
  juan 47f24fe849 breakthrough at changing the contents of widget 3 mesi fa
  juan 8baf399608 fixed issues regarding <script> tags being repeated 3 mesi fa
3 ha cambiato i file con 101 aggiunte e 427 eliminazioni
  1. 95 115
      lib/api_service.dart
  2. 6 0
      lib/augment.dart
  3. 0 312
      lib/home_page.dart

+ 95 - 115
lib/api_service.dart

@@ -3,6 +3,9 @@ import 'package:http/http.dart' as http;
 import 'dart:convert';
 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;
@@ -108,7 +111,6 @@ class _EmailPageState extends State<EmailPage> {
         List<dynamic> json = jsonDecode(response.body);
         for (var item in json) {
           if (item.length > 1 && item[0] is String && item[1] is List) {
-            //  print('Date: ${item[0]}, Threads: ${item[1]}');
             List<int> threadIDs = List<int>.from(item[1]);
             for (var threadId in threadIDs) {
               await fetchThreadMessages(threadId, allEmails);
@@ -125,7 +127,6 @@ class _EmailPageState extends State<EmailPage> {
       emails.clear();
       // emails = messagesMap.values.toList().expand((list) => list).toList();
       emails.addAll(allEmails);
-      // print(emails);
       ;
     });
   }
@@ -135,9 +136,9 @@ class _EmailPageState extends State<EmailPage> {
     try {
       var url = Uri.http(
           '127.0.0.1:3001', 'get_thread_messages', {'id': threadId.toString()});
-      // print(url);
+
       var response = await http.get(url);
-      // print(response.body);
+
       if (response.statusCode == 200) {
         List<dynamic> messagesJson = jsonDecode(response.body);
         List<SerializableMessage> messages =
@@ -156,59 +157,22 @@ class _EmailPageState extends State<EmailPage> {
     String content = r"""
 
     """;
-    // String restcontent = "";
+
     try {
       var url = Uri.http('127.0.0.1:3001', 'email', {'id': id});
-      // print(url);
+
       var response = await http.get(url);
-      // print(response.body);
+
       if (response.statusCode == 200) {
-        print('ok');
         content = response.body;
-        // try {
-        //   var restUrl =
-        //       Uri.http('127.0.0.1:3001', 'get_thread_messages', {'id': id});
-        //   // print(restUrl);
-        //   var restresponse = await http.get(restUrl);
-        //   // print(restresponse.statusCode);
-        //   if (restresponse.statusCode == 200) {
-        //     print("ok squared");
-        //     // restcontent = restresponse.body;
-        //   }
-        // } catch (i) {
-        //   print('jsoncontent caught error: $i');
-        // }
       }
     } catch (e) {
       print('_getEmailContent caught error: $e');
     }
-    // print(content);
-    // print(restcontent);
+
     return content;
   }
 
-  // Future<String> _getThreadMessagesJson(String threadId) async {
-  //   String jsonResponse = "";
-
-  //   try {
-  //     var url =
-  //         Uri.http('127.0.0.1:3001', 'get_thread_messages', {'id': threadId});
-  //     // print(url);
-  //     var response = await http.get(url);
-  //     // print(response.statusCode);
-  //     // print(response.body);
-  //     if (response.statusCode == 200) {
-  //       jsonResponse = response.body; // Here you get the JSON response
-  //     } else {
-  //       throw Exception('Failed to load thread messages');
-  //     }
-  //   } catch (e) {
-  //     print('_getThreadMessagesJson caught error: $e');
-  //   }
-
-  //   return jsonResponse; // Returns the JSON string
-  // }
-
   Future<List<Widget>> _getDrawerItems() async {
     List<String> drawerItems = [];
 
@@ -280,17 +244,14 @@ class _EmailPageState extends State<EmailPage> {
 class EmailListScreen extends StatelessWidget {
   final List emails;
   final Future<String> Function(String) getEmailContent;
-  // final Future<String> Function(String) getJsonEmail;
 
   EmailListScreen({
     required this.emails,
     required this.getEmailContent,
-    // required this.getJsonEmail
   });
 
   @override
   Widget build(BuildContext context) {
-    // print(emails);
     return Scaffold(
       appBar: AppBar(
         title: Text('Emails'),
@@ -310,9 +271,6 @@ class EmailListScreen extends StatelessWidget {
               trailing: Text(emails[index].date.toString()),
               onTap: () async {
                 String emailContent = await getEmailContent(emails[index].id);
-                // String jsonContent =
-                //     await getJsonEmail(emails[index].uid.toString());
-                // print(emails[index]);
                 String from = emails[index].from.toString();
                 String name = emails[index].name.toString();
                 String to = emails[index].to.toString();
@@ -384,80 +342,102 @@ class EmailView extends StatefulWidget {
 
 class _EmailViewState extends State<EmailView> {
   late Key iframeKey;
+  late String currentContent;
+  late String viewTypeId;
 
   @override
   void initState() {
     super.initState();
-    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',
-    );
+    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) {
     return Scaffold(
-      appBar: AppBar(
-        title: Text(widget.name),
-      ),
-      body: Column( 
-        children: [
-          // Container(
-          //   color: Colors.amber,
-          //   child: Text(
-          //     widget.from ,),
-          // ),
-          Row(
-            // title of email
-            children: [
-                Text(
-                widget.subject,
-                style: TextStyle(fontSize: 30),
-                ),
-            ],
-          ),
-          Row(
-            children: [
-              Text(
-                'from ${widget.name}',
-                style: TextStyle(fontSize: 18),
-              ),
-              Text(
-                '<${widget.from}>',
-                style: TextStyle(fontSize: 18),
-              ),
-              Spacer(),
-              Text(
-                '${widget.date}',
-                textAlign: TextAlign.right,
-              )
-            ],
-          ),
-          // TODO: make a case where if one of these is the user's email it just says me :)))))
-          Row(
-            children: [
-              Text(
-                'to ${widget.to.toString()}',
-                style: TextStyle(fontSize: 15),
-              )
-            ],
-          ),
+        appBar: AppBar(
+          title: Text(widget.name),
+        ),
+        body: Column(
+          children: [
+            EmailToolbar(
+              onButtonPressed: () {
+                _registerViewFactory(r"""
+                <h1>Welcome to My Website</h1>
+                <p>This is a simple HTML page.</p>
+                <h2>What is HTML?</h2>
+                <p>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).</p>
+                <h3>Here's a simple list:</h3>
+                <ul>
+                    <li>HTML elements are the building blocks of HTML pages</li>
+                    <li>HTML uses tags like <code>&lt;tag&gt;</code> to organize and format content</li>
+                    <li>CSS is used with HTML to style pages</li>
+                </ul>
+                <p>Copyright © 2023</p>
+                """);
+                print("change");
+                // widget.emailContent = r"
 
-          Expanded(
-            child: HtmlElementView(
-              key: iframeKey,
-              viewType: iframeKey.toString(), 
-        // 'html-view33',
+// "
+              },
             ),
-          )
-        ],
-      )
-    );
+            Row(
+              // title of email
+              children: [
+                Text(
+                  widget.subject,
+                  style: TextStyle(fontSize: 30),
+                ),
+              ],
+            ),
+            Row(
+              children: [
+                Text(
+                  'from ${widget.name}',
+                  style: TextStyle(fontSize: 18),
+                ),
+                Text(
+                  '<${widget.from}>',
+                  style: TextStyle(fontSize: 18),
+                ),
+                Spacer(),
+                Text(
+                  '${widget.date}',
+                  textAlign: TextAlign.right,
+                )
+              ],
+            ),
+            // TODO: make a case where if one of these is the user's email it just says me :)))))
+            Row(
+              children: [
+                Text(
+                  'to ${widget.to.toString()}',
+                  style: TextStyle(fontSize: 15),
+                )
+              ],
+            ),
+
+            Expanded(
+              child: HtmlElementView(
+                key: UniqueKey(),
+                viewType: viewTypeId,
+              ),
+            ),
+          ],
+        ));
   }
 }

+ 6 - 0
lib/augment.dart

@@ -3,6 +3,7 @@ import 'package:http/http.dart' as http;
 import 'dart:convert';
 import 'dart:ui_web' as ui;
 import 'dart:html' as html;
+import 'dart:js' as js;
 
 class EmailToolbar extends StatelessWidget {
   final VoidCallback onButtonPressed;
@@ -22,6 +23,11 @@ class EmailToolbar extends StatelessWidget {
           onPressed: onButtonPressed,
           child: Text('Reload'),
         ),
+        Spacer(),
+        ElevatedButton(
+          onPressed: onButtonPressed,
+          child: Text('Options'),
+        )
       
       ],
     );

File diff suppressed because it is too large
+ 0 - 312
lib/home_page.dart


Some files were not shown because too many files changed in this diff