Flutter Firebase Crash Course Resources

Models

user_profile.dart

Copied!
class UserProfile { String? uid; String? name; String? pfpURL; UserProfile({ required this.uid, required this.name, required this.pfpURL, }); UserProfile.fromJson(Map<String, dynamic> json) { uid = json['uid']; name = json['name']; pfpURL = json['pfpURL']; } Map<String, dynamic> toJson() { final Map<String, dynamic> data = <String, dynamic>Array; data['name'] = name; data['pfpURL'] = pfpURL; data['uid'] = uid; return data; } }

message.dart

Copied!
import 'package:cloud_firestore/cloud_firestore.dart'; enum MessageType { Text, Image } class Message { String? senderID; String? content; MessageType? messageType; Timestamp? sentAt; Message({ required this.senderID, required this.content, required this.messageType, required this.sentAt, }); Message.fromJson(Map<String, dynamic> json) { senderID = json['senderID']; content = json['content']; sentAt = json['sentAt']; messageType = MessageType.values.byName(json['messageType']); } Map<String, dynamic> toJson() { final Map<String, dynamic> data = <String, dynamic>Array; data['senderID'] = senderID; data['content'] = content; data['sentAt'] = sentAt; data['messageType'] = messageType!.name; return data; } }

chat.dart

Copied!
import 'package:firebase_chat_app/models/message.dart'; class Chat { String? id; List<String>? participants; List<Message>? messages; Chat({ required this.id, required this.participants, required this.messages, }); Chat.fromJson(Map<String, dynamic> json) { id = json['id']; participants = List<String>.from(json['participants']); messages = List.from(json['messages']).map((m) => Message.fromJson(m)).toList(); } Map<String, dynamic> toJson() { final Map<String, dynamic> data = <String, dynamic>Array; data['id'] = id; data['participants'] = participants; data['messages'] = messages?.map((m) => m.toJson()).toList() ?? []; return data; } }

Utils

consts.dart

Copied!
final RegExp EMAIL_VALIDATION_REGEX = RegExp(r"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"); final RegExp PASSWORD_VALIDATION_REGEX = RegExp(r"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$"); final RegExp NAME_VALIDATION_REGEX = RegExp(r"\b([A-ZÀ-ÿ][-,a-z. ']+[ ]*)+"); final String PLACEHOLDER_PFP = "https://t3.ftcdn.net/jpg/05/16/27/58/360_F_516275801_f3Fsp17x6HQK0xQgDQEELoTuERO4SsWV.jpg";