mirror of
https://github.com/vleeuwenmenno/supplements.git
synced 2025-09-11 18:29:12 +02:00
feat: adds RDA for intake of vitamins and certain elements based on
canada health values
This commit is contained in:
@@ -10,6 +10,10 @@ enum ThemeOption {
|
||||
class SettingsProvider extends ChangeNotifier {
|
||||
ThemeOption _themeOption = ThemeOption.system;
|
||||
|
||||
// Profile fields
|
||||
DateTime? _dateOfBirth;
|
||||
String? _gender;
|
||||
|
||||
// Time range settings (stored as hours, 0-23)
|
||||
int _morningStart = 5;
|
||||
int _morningEnd = 10;
|
||||
@@ -31,6 +35,19 @@ class SettingsProvider extends ChangeNotifier {
|
||||
|
||||
ThemeOption get themeOption => _themeOption;
|
||||
|
||||
// Profile getters
|
||||
DateTime? get dateOfBirth => _dateOfBirth;
|
||||
String? get gender => _gender;
|
||||
int? get age {
|
||||
if (_dateOfBirth == null) return null;
|
||||
final now = DateTime.now();
|
||||
int years = now.year - _dateOfBirth!.year;
|
||||
final hasHadBirthday = (now.month > _dateOfBirth!.month) ||
|
||||
(now.month == _dateOfBirth!.month && now.day >= _dateOfBirth!.day);
|
||||
if (!hasHadBirthday) years--;
|
||||
return years;
|
||||
}
|
||||
|
||||
// Time range getters
|
||||
int get morningStart => _morningStart;
|
||||
int get morningEnd => _morningEnd;
|
||||
@@ -76,6 +93,13 @@ class SettingsProvider extends ChangeNotifier {
|
||||
final themeIndex = prefs.getInt('theme_option') ?? 0;
|
||||
_themeOption = ThemeOption.values[themeIndex];
|
||||
|
||||
// Load profile fields
|
||||
final dobString = prefs.getString('date_of_birth');
|
||||
if (dobString != null) {
|
||||
_dateOfBirth = DateTime.tryParse(dobString);
|
||||
}
|
||||
_gender = prefs.getString('gender');
|
||||
|
||||
// Load time range settings
|
||||
_morningStart = prefs.getInt('morning_start') ?? 5;
|
||||
_morningEnd = prefs.getInt('morning_end') ?? 10;
|
||||
@@ -106,6 +130,16 @@ class SettingsProvider extends ChangeNotifier {
|
||||
await prefs.setInt('theme_option', option.index);
|
||||
}
|
||||
|
||||
Future<void> setDateOfBirthAndGender(DateTime dateOfBirth, String gender) async {
|
||||
_dateOfBirth = dateOfBirth;
|
||||
_gender = gender;
|
||||
notifyListeners();
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('date_of_birth', dateOfBirth.toIso8601String());
|
||||
await prefs.setString('gender', gender);
|
||||
}
|
||||
|
||||
Future<void> setTimeRanges({
|
||||
required int morningStart,
|
||||
required int morningEnd,
|
||||
|
Reference in New Issue
Block a user