diff --git a/lib/models/notice.dart b/lib/models/notice.dart index ee17f8f..5e4b41a 100644 --- a/lib/models/notice.dart +++ b/lib/models/notice.dart @@ -53,8 +53,10 @@ class TimestampConverter implements JsonConverter { DateTime fromJson(Object timestamp) { if (timestamp is Timestamp) { return timestamp.toDate(); - } else { + } else if (timestamp is String) { return DateTime.parse(timestamp.toString()); + } else { + return DateTime.fromMillisecondsSinceEpoch(timestamp as int); } } diff --git a/lib/models/notice.g.dart b/lib/models/notice.g.dart index 8c2cf14..9760ce5 100644 --- a/lib/models/notice.g.dart +++ b/lib/models/notice.g.dart @@ -12,18 +12,16 @@ Notice _$NoticeFromJson(Map json) { requiredKeys: const [ 'title', 'url', - 'date', 'createdAt', - 'priority', - 'color' + 'color', ], ); return Notice( title: json['title'] as String, url: json['url'] as String, - date: json['date'] as String, + date: (json['date'] ?? '') as String, createdAt: const TimestampConverter().fromJson(json['createdAt']), - priority: json['priority'] as bool, + priority: (json['priority'] ?? false) as bool, color: json['color'] as String, college: json['college'] as String?, tags: (json['tags'] as List?)?.map((e) => e as String?).toList(), diff --git a/lib/widgets/notice_tile.dart b/lib/widgets/notice_tile.dart index beabcf1..80605cc 100644 --- a/lib/widgets/notice_tile.dart +++ b/lib/widgets/notice_tile.dart @@ -326,7 +326,10 @@ class _NoticeTileState extends State { .format(DateTime.parse( widget.document?.createdAt.toString() ?? '0')) .contains('year')) - ? "${widget.document?.date.split('-')[0]} ${DateFormat('MMM').format(DateTime(0, int.parse(widget.document?.date.split('-')[1] ?? '0')))}" + ? widget.document?.date.isNotEmpty == true + ? "${widget.document?.date.split('-')[0]} ${DateFormat('MMM').format(DateTime(0, int.parse(widget.document?.date.split('-')[1] ?? '0')))}" + : DateFormat('dd MMM').format( + widget.document?.createdAt ?? DateTime.now()) : timeago .format(DateTime.parse( widget.document?.createdAt.toString() ?? '0'))