-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMed.dart
130 lines (119 loc) · 3.93 KB
/
Med.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
enum TakeMedResponse { TAKE_MED, NOT_YET, ITS_EXPIRED }
class Med {
String _name;
String _description;
DateTime _expirationDate;
DateTime _lastTimeTaken;
int _timeBetweenUses; // in hours
Med(this._name, this._description, this._expirationDate, this._lastTimeTaken,
this._timeBetweenUses);
void takeMed() {
_lastTimeTaken = DateTime.now();
//_makeTakeMedNotification();
}
bool _isMedExpired() {
if (_expirationDate.isBefore(DateTime.now())) return true;
return false;
}
bool _isMedDue() {
DateTime nextTakingTime =
_lastTimeTaken.add(new Duration(hours: _timeBetweenUses));
if (nextTakingTime.isBefore(DateTime.now())) return true;
return false;
}
TakeMedResponse shouldTakeMed() {
if (_isMedExpired()) return TakeMedResponse.ITS_EXPIRED;
if (_isMedDue())
return TakeMedResponse.TAKE_MED;
else
return TakeMedResponse.NOT_YET;
}
static Widget toWidget(Med med, Color color, bool verbose) {
if (!verbose)
return Column(children: [
Align(
alignment: FractionalOffset(0.1, 0),
child: Text(
med._name,
style: TextStyle(color: color, fontSize: 24),
),
),
SizedBox(height: 15.0),
Align(
alignment: FractionalOffset(0.03, 0),
child: Text(
med._description,
style: TextStyle(color: color, fontSize: 16),
),
),
SizedBox(height: 15.0),
]);
else {
DateTime nextDate = med._lastTimeTaken.add(new Duration(hours: med._timeBetweenUses));
return Column(children: [
Align(
alignment: FractionalOffset(0.03, 0),
child: Text(
med._description,
style: TextStyle(color: color, fontSize: 16),
),
),
SizedBox(height: 15.0),
Align(
alignment: FractionalOffset(0.03, 0),
child: Text(
"Expiration Date: " + new DateFormat.yMMMMEEEEd().format(med.expirationDate),
style: TextStyle(color: color, fontSize: 16),
),
),
SizedBox(height: 15.0),
Align(
alignment: FractionalOffset(0.03, 0),
child: Text(
"Last time the medicine was taken: " + new DateFormat.yMMMMEEEEd().format(med._lastTimeTaken) + " " +
new DateFormat.Hms().format(med._lastTimeTaken),
style: TextStyle(color: color, fontSize: 16),
),
),
SizedBox(height: 15.0),
Align(
alignment: FractionalOffset(0.03, 0),
child: Text(
"Time when you should take it again: " + new DateFormat.yMMMMEEEEd().format(nextDate) + " " +
new DateFormat.Hms().format(nextDate),
style: TextStyle(color: color, fontSize: 16),
),
),
SizedBox(height: 15.0),
Align(
alignment: FractionalOffset(0.03, 0),
child: Text(
"Current date and time: " + new DateFormat.yMMMMEEEEd().format(DateTime.now()) + " " +
new DateFormat.Hms().format(DateTime.now()),
style: TextStyle(color: color, fontSize: 16),
),
),
SizedBox(height: 15.0),
]);
}
}
static Color getColor(Med med) {
TakeMedResponse resp = med.shouldTakeMed();
switch (resp) {
case TakeMedResponse.ITS_EXPIRED:
return Colors.red[500];
case TakeMedResponse.NOT_YET:
return Colors.orange[300];
case TakeMedResponse.TAKE_MED:
return Colors.blue[500];
}
return Colors.black;
}
get name => _name;
get expirationDate => _expirationDate;
get lastTimeTaken => _lastTimeTaken;
get timeBetweenUses => _timeBetweenUses;
get description => _description;
}