-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcourse_activity.dart
92 lines (78 loc) · 3.18 KB
/
course_activity.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// FLUTTER / DART / THIRD-PARTIES
// Package imports:
import 'package:xml/xml.dart';
/// Data-class that represent an activity of a course
class CourseActivity {
/// Course acronym and group
/// Presented like: acronym-group (ex: LOG430-02)
final String courseGroup;
/// Course name
final String courseName;
/// Activity name (ex: "Labo A")
final String activityName;
/// Description of the activity
/// (ex: "Laboratoire (Groupe A)")
final String activityDescription;
/// Place where the activity is given
final String activityLocation;
/// Date when the activity start
final DateTime startDateTime;
/// Date when the activity end
final DateTime endDateTime;
CourseActivity(
{required this.courseGroup,
required this.courseName,
required this.activityName,
required this.activityDescription,
required this.activityLocation,
required this.startDateTime,
required this.endDateTime});
/// Used to create a new [CourseActivity] instance from a [XMLElement].
factory CourseActivity.fromXmlNode(XmlElement node) => CourseActivity(
courseGroup: node.getElement('coursGroupe')!.innerText,
courseName: node.getElement('libelleCours')!.innerText,
activityName: node.getElement('nomActivite')!.innerText,
activityDescription: node.getElement('descriptionActivite')!.innerText,
activityLocation: node.getElement('local')!.innerText,
startDateTime: DateTime.parse(node.getElement('dateDebut')!.innerText),
endDateTime: DateTime.parse(node.getElement('dateFin')!.innerText));
/// Used to create [CourseActivity] instance from a JSON file
factory CourseActivity.fromJson(Map<String, dynamic> map) => CourseActivity(
courseGroup: map['courseGroup'] as String,
courseName: map['courseName'] as String,
activityName: map['activityName'] as String,
activityDescription: map['activityDescription'] as String,
activityLocation: map['activityLocation'] as String,
startDateTime: DateTime.parse(map['startDateTime'] as String),
endDateTime: DateTime.parse(map['endDateTime'] as String));
Map<String, dynamic> toJson() => {
'courseGroup': courseGroup,
'courseName': courseName,
'activityName': activityName,
'activityDescription': activityDescription,
'activityLocation': activityLocation,
'startDateTime': startDateTime.toString(),
'endDateTime': endDateTime.toString()
};
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CourseActivity &&
runtimeType == other.runtimeType &&
courseGroup == other.courseGroup &&
courseName == other.courseName &&
activityName == other.activityName &&
activityDescription == other.activityDescription &&
activityLocation == other.activityLocation &&
startDateTime == other.startDateTime &&
endDateTime == other.endDateTime;
@override
int get hashCode =>
courseGroup.hashCode ^
courseName.hashCode ^
activityName.hashCode ^
activityDescription.hashCode ^
activityLocation.hashCode ^
startDateTime.hashCode ^
endDateTime.hashCode;
}