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

87
lib/models/nutrient.dart Normal file
View File

@@ -0,0 +1,87 @@
class Nutrient {
final String name;
final String unit;
final String rdaType;
final String? note;
final UpperLimit? ul; // nutrient-level UL (optional)
final List<LifeStage> lifeStages;
Nutrient({
required this.name,
required this.unit,
required this.rdaType,
this.note,
this.ul,
required this.lifeStages,
});
factory Nutrient.fromJson(String name, Map<String, dynamic> json) {
return Nutrient(
name: name,
unit: json['unit'],
rdaType: json['rda_type'],
note: json['note'],
ul: (json['ul'] is Map<String, dynamic>) ? UpperLimit.fromJson(json['ul'] as Map<String, dynamic>) : null,
lifeStages: (json['life_stages'] as List)
.map((stage) => LifeStage.fromJson(stage))
.toList(),
);
}
}
class LifeStage {
final String ageRange;
final String sex;
final double value;
final double? valueMin;
final double? valueMax;
final double? ul;
final String? description;
LifeStage({
required this.ageRange,
required this.sex,
required this.value,
this.valueMin,
this.valueMax,
this.ul,
this.description,
});
factory LifeStage.fromJson(Map<String, dynamic> json) {
return LifeStage(
ageRange: json['age_range'],
sex: json['sex'],
value: (json['value'] as num?)?.toDouble() ?? 0.0,
valueMin: json['value_min'] != null ? (json['value_min'] as num).toDouble() : null,
valueMax: json['value_max'] != null ? (json['value_max'] as num).toDouble() : null,
ul: json['ul'] != null ? (json['ul'] as num).toDouble() : null,
description: json['description'],
);
}
}
class UpperLimit {
final double value;
final String unit;
final String? duration;
final String? note;
const UpperLimit({
required this.value,
required this.unit,
this.duration,
this.note,
});
factory UpperLimit.fromJson(Map<String, dynamic> json) {
return UpperLimit(
value: (json['value'] as num).toDouble(),
unit: json['unit'] ?? '',
duration: json['duration'],
note: json['note'],
);
}
}

View File

@@ -2,8 +2,8 @@ import 'dart:convert';
import 'package:uuid/uuid.dart';
import 'ingredient.dart';
import '../services/database_sync_service.dart';
import 'ingredient.dart';
class Supplement {
final int? id;
@@ -69,8 +69,7 @@ class Supplement {
}
Map<String, dynamic> toMap() {
return {
'id': id,
final map = <String, dynamic>{
'name': name,
'brand': brand,
'ingredients': jsonEncode(ingredients.map((ingredient) => ingredient.toMap()).toList()),
@@ -86,6 +85,12 @@ class Supplement {
'syncStatus': syncStatus.name,
'isDeleted': isDeleted ? 1 : 0,
};
if (id != null) {
map['id'] = id;
}
return map;
}
factory Supplement.fromMap(Map<String, dynamic> map) {
@@ -133,6 +138,7 @@ class Supplement {
Supplement copyWith({
int? id,
bool setNullId = false,
String? name,
String? brand,
List<Ingredient>? ingredients,
@@ -144,12 +150,13 @@ class Supplement {
DateTime? createdAt,
bool? isActive,
String? syncId,
bool newSyncId = false,
DateTime? lastModified,
RecordSyncStatus? syncStatus,
bool? isDeleted,
}) {
return Supplement(
id: id ?? this.id,
id: setNullId ? null : (id ?? this.id),
name: name ?? this.name,
brand: brand ?? this.brand,
ingredients: ingredients ?? this.ingredients,
@@ -160,7 +167,7 @@ class Supplement {
notes: notes ?? this.notes,
createdAt: createdAt ?? this.createdAt,
isActive: isActive ?? this.isActive,
syncId: syncId ?? this.syncId,
syncId: newSyncId ? null : (syncId ?? this.syncId),
lastModified: lastModified ?? this.lastModified,
syncStatus: syncStatus ?? this.syncStatus,
isDeleted: isDeleted ?? this.isDeleted,