feat: adds RDA for intake of vitamins and certain elements based on

canada health values
This commit is contained in:
2025-08-28 15:29:20 +02:00
parent 6524e625d8
commit 31e04fe260
24 changed files with 2542 additions and 369 deletions

View File

@@ -7,6 +7,7 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import '../models/supplement.dart';
import '../models/supplement_intake.dart';
import '../services/database_helper.dart';
import '../services/database_sync_service.dart';
import '../services/notification_service.dart';
class SupplementProvider with ChangeNotifier, WidgetsBindingObserver {
@@ -280,6 +281,28 @@ class SupplementProvider with ChangeNotifier, WidgetsBindingObserver {
}
}
Future<void> duplicateSupplement(int supplementId) async {
try {
final originalSupplement = await _databaseHelper.getSupplement(supplementId);
if (originalSupplement != null) {
final newSupplement = originalSupplement.copyWith(
setNullId: true, // This will be a new entry
newSyncId: true, // Generate a new syncId
name: '${originalSupplement.name} (Copy)',
createdAt: DateTime.now(),
lastModified: DateTime.now(),
syncStatus: RecordSyncStatus.pending,
isDeleted: false,
);
await addSupplement(newSupplement);
}
} catch (e) {
if (kDebugMode) {
print('SupplementsLog: Error duplicating supplement: $e');
}
}
}
Future<void> deleteSupplement(int id) async {
try {
await _databaseHelper.deleteSupplement(id);
@@ -420,6 +443,22 @@ class SupplementProvider with ChangeNotifier, WidgetsBindingObserver {
return _todayIntakes.where((intake) => intake['supplement_id'] == supplementId).length;
}
Map<String, double> get dailyIngredientIntake {
final Map<String, double> ingredientIntake = {};
for (final intake in _todayIntakes) {
final supplement = _supplements.firstWhere((s) => s.id == intake['supplement_id']);
final unitsTaken = intake['unitsTaken'] as double;
for (final ingredient in supplement.ingredients) {
final currentAmount = ingredientIntake[ingredient.name] ?? 0;
ingredientIntake[ingredient.name] = currentAmount + (ingredient.amount * unitsTaken);
}
}
return ingredientIntake;
}
// Method to manually refresh daily status (useful for testing or manual refresh)
Future<void> refreshDailyStatus() async {
if (kDebugMode) {