Skip to content

Implement userTargetWeightDate #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion app/lib/core/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class Preferences {
/// default for userTargetWeight in kg
final double defaultUserTargetWeight = -1;

/// default for userTargetWeight in kg
/// default for when to reach userTargetWeight
final int defaultUserTargetWeightDate = 0;

/// default for userTargetHeight in kg
final double defaultUserWeight = 70;

/// default for userHeight in m
Expand Down Expand Up @@ -122,6 +125,17 @@ class Preferences {
? prefs.getDouble('userTargetWeight')!
: null;

/// set date for when to reaching the user target weight
set userTargetWeightDate(DateTime? date) => prefs.setInt(
'userTargetWeight',
date?.millisecondsSinceEpoch ?? 0,
);

/// get user target weight date
DateTime? get userTargetWeightDate => prefs.getInt('userTargetWeight')! > 0
? DateTime.fromMillisecondsSinceEpoch(prefs.getInt('userTargetWeight')!)
: null;

/// set if onboarding screen is shown
set showOnBoarding(bool show) => prefs.setBool('showOnBoarding', show);

Expand Down Expand Up @@ -272,6 +286,9 @@ class Preferences {
if (override || !prefs.containsKey('userTargetWeight')) {
userTargetWeight = defaultUserTargetWeight;
}
if (override || !prefs.containsKey('userTargetWeightDate')) {
userTargetWeightDate = DateTime.fromMillisecondsSinceEpoch(defaultUserTargetWeightDate);
}
if (override || !prefs.containsKey('userHeight')) {
userHeight = defaultUserHeight;
}
Expand Down