From 84c50d7b97b16e4d0f580f007b35f268c9c6df68 Mon Sep 17 00:00:00 2001 From: juan Date: Fri, 20 Sep 2024 00:37:33 -0400 Subject: [PATCH] made this file to keep the model of emails (soon to be more moved here) --- lib/structs.dart | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lib/structs.dart diff --git a/lib/structs.dart b/lib/structs.dart new file mode 100644 index 0000000..09b42ef --- /dev/null +++ b/lib/structs.dart @@ -0,0 +1,47 @@ +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; +import 'dart:convert'; +import 'dart:ui_web' as ui; +import 'dart:html' as html; +import 'augment.dart'; +import 'dart:js' as js; +import 'api_service.dart'; +import 'dart:convert'; // For JSON decoding +import 'package:intl/intl.dart'; + + +class GetThreadResponse { + final int id; + final List messages; + final String subject; + final DateTime date; + final String from_name; + final String from_address; + final List to; + + GetThreadResponse({ + required this.id, + required this.messages, + required this.subject, + required this.date, + required this.from_name, + required this.from_address, + required this.to, + }); + factory GetThreadResponse.fromJson(Map json) { + var messagesList = json['messages'] as List; + var toList = json['to'] as List; + // var ccList = json['cc'] as List; + + return GetThreadResponse ( + id: json['id'], + // messages: messagesList.map((message) => message.toString()).toList(), + messages: List.from(json['messages']), + subject: json['subject'], + date: DateTime.parse(json['date']), + from_name: json['from_name'], + from_address: json['from_address'], + to: toList.map((i)=> MailAddress.fromJson(i)).toList(), + ); + } +}