title: Getting all the emails into a list using IMAP
body: <p>I am trying to create an mail app in Flutter, right now I am testing the back end then I want to integrate it in my app.</p>
  
  <p>I am using IMAP to get all my emails from my university and insert them into a list using a class called Emails with parameters like subject, date, from, to and body  (all string types).</p>
  
  <pre><code>    List emails;
    Future&lt;EMails&gt; getEmails() async {
      ImapFolder inbox = await client.getFolder("inbox");
      EMails list;
      for (var i = inbox.mailCount; i &gt; 0; i--) {
        list.subject = await inbox.fetch(["BODY.PEEK[HEADER.FIELDS (SUBJECT)]"],
            messageIds: [i]) as String; //gets the subject
        list.date = await inbox.fetch(["BODY.PEEK[HEADER.FIELDS (Date)]"],
            messageIds: [i]) as String; //gets the Date
        list.from = await inbox.fetch(["BODY.PEEK[HEADER.FIELDS (From)]"],
            messageIds: [i]) as String; //gets the From
        list.to =
            await inbox.fetch(["BODY.PEEK[HEADER.FIELDS (To)]"], messageIds: [i])
                as String; //gets the To
        list.body = await inbox.fetch(["RFC822.TEXT"], messageIds: [i]) as String;
        emails.add(list);
      }
      return list;
    }
  </code></pre>
  
  <p>The problem is that I can't transform my fetching data into strings.
     <a href="https://i.imgur.com/vP91ZG1.png" rel="nofollow noreferrer">https://i.imgur.com/vP91ZG1.png</a></p>