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 'dart:typed_data';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
 | 
					import 'package:pointer_interceptor/pointer_interceptor.dart';
 | 
				
			||||||
 | 
					import 'collapsableEmails.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import 'structs.dart';
 | 
					import 'structs.dart';
 | 
				
			||||||
import 'package:flutter/material.dart';
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
| 
						 | 
					@ -111,11 +113,13 @@ class ApiService {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //returns the html for the email, it gets used in emailView
 | 
					  //returns the html for the email, it gets used in emailView
 | 
				
			||||||
  Future<String> fetchEmailContent(
 | 
					  Future<List<String>> fetchEmailContent(
 | 
				
			||||||
      List<String> IDsString, String emailFolder) async {
 | 
					      List<String> IDsString, String emailFolder) async {
 | 
				
			||||||
    String content = r"""
 | 
					    String content = r"""
 | 
				
			||||||
    """;
 | 
					    """;
 | 
				
			||||||
 | 
					    List<String> HTMLofThread = [];
 | 
				
			||||||
    threadAttachments = [];
 | 
					    threadAttachments = [];
 | 
				
			||||||
 | 
					    int counter = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      //attaches email after email from a thread
 | 
					      //attaches email after email from a thread
 | 
				
			||||||
| 
						 | 
					@ -124,7 +128,9 @@ class ApiService {
 | 
				
			||||||
        var response = await http.get(url);
 | 
					        var response = await http.get(url);
 | 
				
			||||||
        currThread.add(id);
 | 
					        currThread.add(id);
 | 
				
			||||||
        if (response.statusCode == 200) {
 | 
					        if (response.statusCode == 200) {
 | 
				
			||||||
 | 
					          counter += 1;
 | 
				
			||||||
          content += response.body;
 | 
					          content += response.body;
 | 
				
			||||||
 | 
					          HTMLofThread.add(response.body);
 | 
				
			||||||
          try {
 | 
					          try {
 | 
				
			||||||
            List<AttachmentInfo> attachments =
 | 
					            List<AttachmentInfo> attachments =
 | 
				
			||||||
                await getAttachmentsInfo(emailFolder, id);
 | 
					                await getAttachmentsInfo(emailFolder, id);
 | 
				
			||||||
| 
						 | 
					@ -138,13 +144,14 @@ class ApiService {
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          content +=
 | 
					          content +=
 | 
				
			||||||
              """<div id="JuanBedarramarker" style="width: 10px; height: 30px;"></div>""";
 | 
					              """<div id="JuanBedarramarker" style="width: 10px; height: 30px;"></div>""";
 | 
				
			||||||
          content += "<hr>";
 | 
					          content += "<hr><p>end of email</p>";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e) {
 | 
				
			||||||
      print('_getEmailContent caught error: $e');
 | 
					      print('_getEmailContent caught error: $e');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return content;
 | 
					    // return content;
 | 
				
			||||||
 | 
					    return HTMLofThread;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Future<List<SerializableMessage>> threadsInSerializable(
 | 
					  Future<List<SerializableMessage>> threadsInSerializable(
 | 
				
			||||||
| 
						 | 
					@ -419,13 +426,14 @@ class ApiService {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class EmailView extends StatefulWidget {
 | 
					class EmailView extends StatefulWidget {
 | 
				
			||||||
  final String emailContent;
 | 
					  final List<String> emailContent;
 | 
				
			||||||
  final String from;
 | 
					  final String from;
 | 
				
			||||||
  final String name;
 | 
					  final String name;
 | 
				
			||||||
  final String to;
 | 
					  final String to;
 | 
				
			||||||
  final String subject;
 | 
					  final String subject;
 | 
				
			||||||
  final String date;
 | 
					  final String date;
 | 
				
			||||||
  final String id;
 | 
					  final String id;
 | 
				
			||||||
 | 
					  final List<String> messages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const EmailView({
 | 
					  const EmailView({
 | 
				
			||||||
    Key? key,
 | 
					    Key? key,
 | 
				
			||||||
| 
						 | 
					@ -436,6 +444,7 @@ class EmailView extends StatefulWidget {
 | 
				
			||||||
    required this.subject,
 | 
					    required this.subject,
 | 
				
			||||||
    required this.date,
 | 
					    required this.date,
 | 
				
			||||||
    required this.id,
 | 
					    required this.id,
 | 
				
			||||||
 | 
					    required this.messages,
 | 
				
			||||||
  }) : super(key: key);
 | 
					  }) : super(key: key);
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
  _EmailViewState createState() => _EmailViewState();
 | 
					  _EmailViewState createState() => _EmailViewState();
 | 
				
			||||||
| 
						 | 
					@ -445,7 +454,7 @@ class _EmailViewState extends State<EmailView> {
 | 
				
			||||||
  //html css rendering thing
 | 
					  //html css rendering thing
 | 
				
			||||||
  late Key iframeKey;
 | 
					  late Key iframeKey;
 | 
				
			||||||
  late String currentContent;
 | 
					  late String currentContent;
 | 
				
			||||||
  late String viewTypeId;
 | 
					  late String viewTypeId; //make this a list too???
 | 
				
			||||||
  Future<List<Map<String, dynamic>>>? _markerPositionsFuture;
 | 
					  Future<List<Map<String, dynamic>>>? _markerPositionsFuture;
 | 
				
			||||||
  // TextEditingController _jumpController = TextEditingController();
 | 
					  // TextEditingController _jumpController = TextEditingController();
 | 
				
			||||||
  final hardcodedMarkers = [
 | 
					  final hardcodedMarkers = [
 | 
				
			||||||
| 
						 | 
					@ -458,33 +467,37 @@ class _EmailViewState extends State<EmailView> {
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
  void initState() {
 | 
					  void initState() {
 | 
				
			||||||
    super.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
 | 
					        .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
 | 
					    // 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);
 | 
					    _registerViewFactory(currentContent);
 | 
				
			||||||
    // _markerPositionsFuture = ApiService().getMarkerPosition();
 | 
					    // _markerPositionsFuture = ApiService().getMarkerPosition();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void _registerViewFactory(String currentContent) {
 | 
					  void _registerViewFactory(List<String> currentContent) {
 | 
				
			||||||
    setState(() {
 | 
					    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}';
 | 
					      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(
 | 
					      ui.platformViewRegistry.registerViewFactory(
 | 
				
			||||||
        viewTypeId,
 | 
					        viewTypeId,
 | 
				
			||||||
          (int viewId) => web.HTMLDivElement()
 | 
					        (int viewId) => emailHTML,
 | 
				
			||||||
            ..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');
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -565,13 +578,18 @@ class _EmailViewState extends State<EmailView> {
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
                  ],
 | 
					                  ],
 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
 | 
					 | 
				
			||||||
                Expanded(
 | 
					                Expanded(
 | 
				
			||||||
                  child: HtmlElementView(
 | 
					                  child: CollapsableEmails(
 | 
				
			||||||
                    key: UniqueKey(),
 | 
					                    thread: widget.messages,
 | 
				
			||||||
                    viewType: viewTypeId,
 | 
					                    threadHTML: widget.emailContent,
 | 
				
			||||||
                  ),
 | 
					                  ),
 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
 | 
					                // Expanded(
 | 
				
			||||||
 | 
					                //   child: HtmlElementView(
 | 
				
			||||||
 | 
					                //     key: UniqueKey(),
 | 
				
			||||||
 | 
					                //     viewType: viewTypeId,
 | 
				
			||||||
 | 
					                //   ),
 | 
				
			||||||
 | 
					                // ),
 | 
				
			||||||
              ],
 | 
					              ],
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue