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
This commit is contained in:
		
							parent
							
								
									c9c239767a
								
							
						
					
					
						commit
						c77eb114b7
					
				
					 1 changed files with 46 additions and 28 deletions
				
			
		| 
						 | 
				
			
			@ -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<String> fetchEmailContent(
 | 
			
		||||
  Future<List<String>> fetchEmailContent(
 | 
			
		||||
      List<String> IDsString, String emailFolder) async {
 | 
			
		||||
    String content = r"""
 | 
			
		||||
    """;
 | 
			
		||||
    List<String> 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<AttachmentInfo> attachments =
 | 
			
		||||
                await getAttachmentsInfo(emailFolder, id);
 | 
			
		||||
| 
						 | 
				
			
			@ -138,13 +144,14 @@ class ApiService {
 | 
			
		|||
          }
 | 
			
		||||
          content +=
 | 
			
		||||
              """<div id="JuanBedarramarker" style="width: 10px; height: 30px;"></div>""";
 | 
			
		||||
          content += "<hr>";
 | 
			
		||||
          content += "<hr><p>end of email</p>";
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      print('_getEmailContent caught error: $e');
 | 
			
		||||
    }
 | 
			
		||||
    return content;
 | 
			
		||||
    // return content;
 | 
			
		||||
    return HTMLofThread;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<List<SerializableMessage>> threadsInSerializable(
 | 
			
		||||
| 
						 | 
				
			
			@ -419,13 +426,14 @@ class ApiService {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
class EmailView extends StatefulWidget {
 | 
			
		||||
  final String emailContent;
 | 
			
		||||
  final List<String> emailContent;
 | 
			
		||||
  final String from;
 | 
			
		||||
  final String name;
 | 
			
		||||
  final String to;
 | 
			
		||||
  final String subject;
 | 
			
		||||
  final String date;
 | 
			
		||||
  final String id;
 | 
			
		||||
  final List<String> 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<EmailView> {
 | 
			
		|||
  //html css rendering thing
 | 
			
		||||
  late Key iframeKey;
 | 
			
		||||
  late String currentContent;
 | 
			
		||||
  late String viewTypeId;
 | 
			
		||||
  late String viewTypeId; //make this a list too???
 | 
			
		||||
  Future<List<Map<String, dynamic>>>? _markerPositionsFuture;
 | 
			
		||||
  // TextEditingController _jumpController = TextEditingController();
 | 
			
		||||
  final hardcodedMarkers = [
 | 
			
		||||
| 
						 | 
				
			
			@ -458,33 +467,37 @@ class _EmailViewState extends State<EmailView> {
 | 
			
		|||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    super.initState();
 | 
			
		||||
    String currentContent = widget
 | 
			
		||||
    List<String> 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<String> 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');
 | 
			
		||||
        (int viewId) => emailHTML,
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -565,13 +578,18 @@ class _EmailViewState extends State<EmailView> {
 | 
			
		|||
                    )
 | 
			
		||||
                  ],
 | 
			
		||||
                ),
 | 
			
		||||
 | 
			
		||||
                Expanded(
 | 
			
		||||
                  child: HtmlElementView(
 | 
			
		||||
                    key: UniqueKey(),
 | 
			
		||||
                    viewType: viewTypeId,
 | 
			
		||||
                  child: CollapsableEmails(
 | 
			
		||||
                    thread: widget.messages,
 | 
			
		||||
                    threadHTML: widget.emailContent,
 | 
			
		||||
                  ),
 | 
			
		||||
                ),
 | 
			
		||||
                // Expanded(
 | 
			
		||||
                //   child: HtmlElementView(
 | 
			
		||||
                //     key: UniqueKey(),
 | 
			
		||||
                //     viewType: viewTypeId,
 | 
			
		||||
                //   ),
 | 
			
		||||
                // ),
 | 
			
		||||
              ],
 | 
			
		||||
            ),
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue