initial commit

Signed-off-by: Menno van Leeuwen <menno@vleeuwen.me>
This commit is contained in:
2025-08-26 01:21:26 +02:00
commit f8c19f9051
132 changed files with 7054 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
class Supplement {
final int? id;
final String name;
final double dosageAmount; // Amount per unit (e.g., 187mg)
final int numberOfUnits; // Number of units to take (e.g., 2 capsules)
final String unit; // mg, g, ml, etc.
final String unitType; // capsules, tablets, ml, etc.
final int frequencyPerDay;
final List<String> reminderTimes; // e.g., ['08:00', '20:00']
final String? notes;
final DateTime createdAt;
final bool isActive;
Supplement({
this.id,
required this.name,
required this.dosageAmount,
required this.numberOfUnits,
required this.unit,
required this.unitType,
required this.frequencyPerDay,
required this.reminderTimes,
this.notes,
required this.createdAt,
this.isActive = true,
});
// Helper getter for total dosage per intake
double get totalDosagePerIntake => dosageAmount * numberOfUnits;
Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
'dosageAmount': dosageAmount,
'numberOfUnits': numberOfUnits,
'unit': unit,
'unitType': unitType,
'frequencyPerDay': frequencyPerDay,
'reminderTimes': reminderTimes.join(','),
'notes': notes,
'createdAt': createdAt.toIso8601String(),
'isActive': isActive ? 1 : 0,
};
}
factory Supplement.fromMap(Map<String, dynamic> map) {
return Supplement(
id: map['id'],
name: map['name'],
dosageAmount: map['dosageAmount']?.toDouble() ?? map['dosage']?.toDouble() ?? 0.0, // Backwards compatibility
numberOfUnits: map['numberOfUnits'] ?? 1, // Default to 1 for backwards compatibility
unit: map['unit'],
unitType: map['unitType'] ?? 'units', // Default unit type for backwards compatibility
frequencyPerDay: map['frequencyPerDay'],
reminderTimes: map['reminderTimes'].split(','),
notes: map['notes'],
createdAt: DateTime.parse(map['createdAt']),
isActive: map['isActive'] == 1,
);
}
Supplement copyWith({
int? id,
String? name,
double? dosageAmount,
int? numberOfUnits,
String? unit,
String? unitType,
int? frequencyPerDay,
List<String>? reminderTimes,
String? notes,
DateTime? createdAt,
bool? isActive,
}) {
return Supplement(
id: id ?? this.id,
name: name ?? this.name,
dosageAmount: dosageAmount ?? this.dosageAmount,
numberOfUnits: numberOfUnits ?? this.numberOfUnits,
unit: unit ?? this.unit,
unitType: unitType ?? this.unitType,
frequencyPerDay: frequencyPerDay ?? this.frequencyPerDay,
reminderTimes: reminderTimes ?? this.reminderTimes,
notes: notes ?? this.notes,
createdAt: createdAt ?? this.createdAt,
isActive: isActive ?? this.isActive,
);
}
}

View File

@@ -0,0 +1,57 @@
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,
);
}
}