소스 검색

shorter time to collect threads due to new endpoint, and fixed the view for emails (needs improvement tho)

juan 4 시간 전
부모
커밋
254972d2af
1개의 변경된 파일13개의 추가작업 그리고 11개의 파일을 삭제
  1. 13 11
      lib/api_service.dart

+ 13 - 11
lib/api_service.dart

@@ -124,9 +124,9 @@ class _EmailPageState extends State<EmailPage> {
     setState(() {
       emails = allEmails;
     });
-    print(emails[0]);
+    // print(emails[0]);
     // Print allEmails to debug its structure
-    print("allEmails: ${allEmails[0].messages}");
+    // print("allEmails: ${allEmails[0].messages}");
 
     // Convert allEmails to a list
   }
@@ -188,23 +188,24 @@ class _EmailPageState extends State<EmailPage> {
   //   }
   // }
 
-  Future<String> _getEmailContent(String id) async {
+  Future<String> _getEmailContent(List<String> IDs) async {
     String content = r"""
-
     """;
 
     try {
-      var url = Uri.http('127.0.0.1:3001', 'email', {'id': id});
+      for (var id in IDs) {
+        var url = Uri.http('127.0.0.1:3001', 'email', {'id': id});
 
-      var response = await http.get(url);
+        var response = await http.get(url);
 
-      if (response.statusCode == 200) {
-        content = response.body;
+        if (response.statusCode == 200) {
+          content += response.body;
+        }
       }
     } catch (e) {
       print('_getEmailContent caught error: $e');
     }
-
+    print(content);
     return content;
   }
 
@@ -280,7 +281,7 @@ class EmailListScreen extends StatelessWidget {
   //this is the bulding of the drawer with all emails
   // try to only get the subject and id, date, sender to make it faster
   final List emails;
-  final Future<String> Function(String) getEmailContent;
+  final Future<String> Function(List<String>) getEmailContent;
 
   EmailListScreen({
     required this.emails,
@@ -309,7 +310,8 @@ class EmailListScreen extends StatelessWidget {
               //here we assign each part of json to a var, this could be changed so it only happens,
               // when clicking on email for modularity
               onTap: () async {
-                String emailContent = await getEmailContent(emails[index].id);
+                String emailContent =
+                    await getEmailContent(emails[index].messages);
                 String messages = emails[index].messages.toString();
                 String fromName = emails[index].from_name.toString();
                 String fromAddress = emails[index].from_address.toString();