add structure
This commit is contained in:
38
lib/vo/announcement.dart
Normal file
38
lib/vo/announcement.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
class Announcement {
|
||||
String id;
|
||||
String name;
|
||||
String text;
|
||||
DateTime time;
|
||||
|
||||
Announcement({this.id, this.name, this.text, this.time});
|
||||
|
||||
bool fromToday() {
|
||||
var now = DateTime.now();
|
||||
if (time == null) return false;
|
||||
return time.day == now.day &&
|
||||
time.month == now.month &&
|
||||
time.year == now.year;
|
||||
}
|
||||
|
||||
factory Announcement.fromMap(Map<String, dynamic> map, String id) {
|
||||
var _time = (map['time'] as Timestamp);
|
||||
|
||||
return Announcement(
|
||||
id: id,
|
||||
time: _time?.toDate(),
|
||||
name: map['name'],
|
||||
text: map['text'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {'id': id, 'name': name, 'text': text};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Announcement{id:$id,name:$name,text:$text}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user