check null safety

This commit is contained in:
tzw
2021-09-10 14:27:38 +06:30
parent a144c945b6
commit 7670779b03
57 changed files with 620 additions and 626 deletions

View File

@@ -1,15 +1,15 @@
import 'package:cloud_firestore/cloud_firestore.dart';
class Message {
String id;
String message;
DateTime date;
String receiverID;
String receiverName;
String senderID;
String senderName;
String messageType;
String messageID;
String? id;
String? message;
DateTime? date;
String? receiverID;
String? receiverName;
String? senderID;
String? senderName;
String? messageType;
String? messageID;
Message(
{this.id,
@@ -21,11 +21,13 @@ class Message {
this.senderName,
this.messageType,
this.messageID});
bool fromToday() {
if (date == null) return false;
var now = DateTime.now();
return date.day == now.day &&
date.month == now.month &&
date.year == now.year;
return date!.day == now.day &&
date!.month == now.month &&
date!.year == now.year;
}
Map<String, dynamic> toMap() {
@@ -36,9 +38,10 @@ class Message {
}
bool sameDay(Message another) {
return date.year == another.date.year &&
date.month == another.date.month &&
date.day == another.date.day;
if (date == null) return false;
return date!.year == another.date!.year &&
date!.month == another.date!.month &&
date!.day == another.date!.day;
}
factory Message.fromMap(Map<String, dynamic> map, String id) {
@@ -52,7 +55,7 @@ class Message {
receiverName: map['receiver_name'],
messageType: map['msg_type'],
messageID: map['msg_id'],
date: date != null ? date.toDate() : null,
date: date.toDate(),
);
}
}