Refactor supplement intake handling to support fractional units and update notification service initialization for Linux

This commit is contained in:
2025-08-26 01:35:43 +02:00
parent 05a9d13164
commit e6181add08
7 changed files with 127 additions and 54 deletions

View File

@@ -103,13 +103,13 @@ class SupplementProvider with ChangeNotifier {
}
}
Future<void> recordIntake(int supplementId, double dosage, {int? unitsTaken, String? notes}) async {
Future<void> recordIntake(int supplementId, double dosage, {double? unitsTaken, String? notes}) async {
try {
final intake = SupplementIntake(
supplementId: supplementId,
takenAt: DateTime.now(),
dosageTaken: dosage,
unitsTaken: unitsTaken ?? 1,
unitsTaken: unitsTaken ?? 1.0,
notes: notes,
);
@@ -118,7 +118,7 @@ class SupplementProvider with ChangeNotifier {
// Show confirmation notification
final supplement = _supplements.firstWhere((s) => s.id == supplementId);
final unitsText = unitsTaken != null && unitsTaken > 1 ? '$unitsTaken ${supplement.unitType}' : '';
final unitsText = unitsTaken != null && unitsTaken != 1 ? '${unitsTaken.toStringAsFixed(unitsTaken % 1 == 0 ? 0 : 1)} ${supplement.unitType}' : '';
await _notificationService.showInstantNotification(
'Supplement Taken',
'Recorded ${supplement.name}${unitsText.isNotEmpty ? ' - $unitsText' : ''} ($dosage ${supplement.unit})',