Files
supplements/lib/models/supplement_intake.dart
Menno van Leeuwen f8c19f9051 initial commit
Signed-off-by: Menno van Leeuwen <menno@vleeuwen.me>
2025-08-26 01:21:26 +02:00

58 lines
1.4 KiB
Dart

class SupplementIntake {
final int? id;
final int supplementId;
final DateTime takenAt;
final double dosageTaken; // Total dosage amount taken
final int unitsTaken; // Number of units taken
final String? notes;
SupplementIntake({
this.id,
required this.supplementId,
required this.takenAt,
required this.dosageTaken,
required this.unitsTaken,
this.notes,
});
Map<String, dynamic> toMap() {
return {
'id': id,
'supplementId': supplementId,
'takenAt': takenAt.toIso8601String(),
'dosageTaken': dosageTaken,
'unitsTaken': unitsTaken,
'notes': notes,
};
}
factory SupplementIntake.fromMap(Map<String, dynamic> map) {
return SupplementIntake(
id: map['id'],
supplementId: map['supplementId'],
takenAt: DateTime.parse(map['takenAt']),
dosageTaken: map['dosageTaken'],
unitsTaken: map['unitsTaken'] ?? 1, // Default for backwards compatibility
notes: map['notes'],
);
}
SupplementIntake copyWith({
int? id,
int? supplementId,
DateTime? takenAt,
double? dosageTaken,
int? unitsTaken,
String? notes,
}) {
return SupplementIntake(
id: id ?? this.id,
supplementId: supplementId ?? this.supplementId,
takenAt: takenAt ?? this.takenAt,
dosageTaken: dosageTaken ?? this.dosageTaken,
unitsTaken: unitsTaken ?? this.unitsTaken,
notes: notes ?? this.notes,
);
}
}