import 'package:cloud_firestore/cloud_firestore.dart'; import '../constants.dart'; class Message { final String senderID; final String senderEmail; final String receiverID; final String message; final Timestamp timestamp; Message({ required this.senderID, required this.senderEmail, required this.receiverID, required this.message, required this.timestamp, }); // convert to a map Map toMap() { return { Constants.dbFieldMessageSenderId: senderID, Constants.dbFieldMessageSenderEmail: senderEmail, Constants.dbFieldMessageReceiverId: receiverID, Constants.dbFieldMessageText: message, Constants.dbFieldMessageTimestamp: timestamp, }; } // create Message from map factory Message.fromMap(Map map) { return Message( senderID: map[Constants.dbFieldMessageSenderId], senderEmail: map[Constants.dbFieldMessageSenderEmail], receiverID: map[Constants.dbFieldMessageReceiverId], message: map[Constants.dbFieldMessageText], timestamp: map[Constants.dbFieldMessageTimestamp], ); } }