From c77eb114b7b888c5487ab4efaf0304853ac12168 Mon Sep 17 00:00:00 2001 From: juan Date: Sun, 18 May 2025 20:51:21 -0400 Subject: [PATCH] added more member variables to EmailView so i can render html differently, and also changed the way how html is being handled and call CollapsableEmails --- lib/api_service.dart | 74 +++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/lib/api_service.dart b/lib/api_service.dart index cc2c719..a9b6b20 100644 --- a/lib/api_service.dart +++ b/lib/api_service.dart @@ -5,6 +5,8 @@ import 'dart:async'; import 'dart:typed_data'; import 'package:pointer_interceptor/pointer_interceptor.dart'; +import 'collapsableEmails.dart'; + import 'structs.dart'; import 'package:flutter/material.dart'; @@ -111,11 +113,13 @@ class ApiService { } //returns the html for the email, it gets used in emailView - Future fetchEmailContent( + Future> fetchEmailContent( List IDsString, String emailFolder) async { String content = r""" """; + List HTMLofThread = []; threadAttachments = []; + int counter = 0; try { //attaches email after email from a thread @@ -124,7 +128,9 @@ class ApiService { var response = await http.get(url); currThread.add(id); if (response.statusCode == 200) { + counter += 1; content += response.body; + HTMLofThread.add(response.body); try { List attachments = await getAttachmentsInfo(emailFolder, id); @@ -138,13 +144,14 @@ class ApiService { } content += """
"""; - content += "
"; + content += "

end of email

"; } } } catch (e) { print('_getEmailContent caught error: $e'); } - return content; + // return content; + return HTMLofThread; } Future> threadsInSerializable( @@ -419,13 +426,14 @@ class ApiService { } class EmailView extends StatefulWidget { - final String emailContent; + final List emailContent; final String from; final String name; final String to; final String subject; final String date; final String id; + final List messages; const EmailView({ Key? key, @@ -436,6 +444,7 @@ class EmailView extends StatefulWidget { required this.subject, required this.date, required this.id, + required this.messages, }) : super(key: key); @override _EmailViewState createState() => _EmailViewState(); @@ -445,7 +454,7 @@ class _EmailViewState extends State { //html css rendering thing late Key iframeKey; late String currentContent; - late String viewTypeId; + late String viewTypeId; //make this a list too??? Future>>? _markerPositionsFuture; // TextEditingController _jumpController = TextEditingController(); final hardcodedMarkers = [ @@ -458,33 +467,37 @@ class _EmailViewState extends State { @override void initState() { super.initState(); - String currentContent = widget + List currentContent = widget .emailContent; //html of the email/ actually entire thread, gives me little space to play in between // i wonder if the other attributes change? because if so i have to add like some zooms in and out of the emails, as in collapse - viewTypeId = "iframe-${DateTime.now().millisecondsSinceEpoch}"; + // viewTypeId = "iframe-${DateTime.now().millisecondsSinceEpoch}"; _registerViewFactory(currentContent); // _markerPositionsFuture = ApiService().getMarkerPosition(); } - void _registerViewFactory(String currentContent) { - setState(() { + void _registerViewFactory(List currentContent) { + setState(() { //update to do item per item + // each item to have itsviewtype ID + // is this necessarey here?? + + //could just move to collapsable + + + viewTypeId = 'iframe-${DateTime.now().millisecondsSinceEpoch}'; + final emailHTML = web.document.createElement('div') as web.HTMLDivElement + ..id = viewTypeId + ..innerHTML = currentContent[0].toJS; // temporarily index because it has to do all of them + emailHTML.style + ..width = '100%' + ..height = '100%' + ..overflow = 'auto' + ..scrollBehavior = 'smooth'; + ui.platformViewRegistry.registerViewFactory( - viewTypeId, - (int viewId) => web.HTMLDivElement() - ..id = 'new-web' - ..innerHTML = currentContent as js.JSAny); - - // DivElement div = HTMLDivElement() - // ..id = - - // ui.platformViewRegistry.registerViewFactory( - // viewTypeId, - // (int viewId) => html.IFrameElement() - // ..width = '100%' - // ..height = '100%' - // ..srcdoc = currentContent - // ..style.border = 'none'); + viewTypeId, + (int viewId) => emailHTML, + ); }); } @@ -565,13 +578,18 @@ class _EmailViewState extends State { ) ], ), - Expanded( - child: HtmlElementView( - key: UniqueKey(), - viewType: viewTypeId, + child: CollapsableEmails( + thread: widget.messages, + threadHTML: widget.emailContent, ), ), + // Expanded( + // child: HtmlElementView( + // key: UniqueKey(), + // viewType: viewTypeId, + // ), + // ), ], ),