Core models
User
TheUser class stores account information and personal details for health calculations.
Defined in: main.dart:56-125
User’s first name
User’s last name
Gender:
"masculino" or "femenino" (used for hydration goal calculation)Age in years (used for hydration goal adjustments)
Height in centimeters
Weight in kilograms (used for hydration goal calculation: weight × 35ml)
Email address (used as unique identifier/primary key)
Password (stored in plain text - not recommended for production)
Theme brightness:
"light" or "dark". Defaults to system preference if null.ARGB color value for Material 3 theme. Example:
0xFF8BC34A for lime green.Font family name:
null (system default) or "serif"Whether to use GPS for exercise tracking. Defaults to
false.- Box:
users - Key:
user:{correo} - Example:
user:[email protected]
UserSettings
TheUserSettings class stores user preferences separate from the User model.
Defined in: main.dart:161-200
User email (foreign key to User)
Theme brightness:
"light" or "dark"ARGB color value for theming
Font family:
null or "serif"GPS tracking enabled for exercise
Custom daily hydration goal in milliliters. If null, auto-calculated from weight/age/gender.
- Box:
user_settings - Key:
settings:{userId} - Example:
settings:[email protected]
Daily data models
All daily data uses composite keys:{userId}_{YYYY-MM-DD}
Exercise data
Box:daily_exerciseKey pattern:
{email}_{date}Example key:
[email protected]_2026-03-04
Total steps counted for the day
Distance traveled in kilometers (if GPS enabled)
Estimated calories burned
Current activity:
"stationary", "walking", "running", or "vehicle"ISO 8601 timestamp of last step count update
Hydration logs
Box:hydration_logsKey pattern:
{email}_{date}_{timestamp}Example key:
[email protected]_2026-03-04_1709553600
Individual water intake events (e.g., +250ml at 14:30).
User email
Milliliters consumed in this event (100, 250, or 500)
ISO 8601 timestamp of when water was logged
Hydration summary
Box:daily_hydration_summaryKey pattern:
{email}_{date}Example key:
[email protected]_2026-03-04
Daily total of water consumed.
Total milliliters consumed for the day
Daily hydration goal (from user settings or auto-calculated)
Progress percentage:
(total_ml / goal_ml) * 100Sleep data
Box:daily_sleepKey pattern:
{email}_{date}Example key:
[email protected]_2026-03-04
Sleep session recorded for a given night.
ISO 8601 timestamp of sleep start time (when screen turned off)
ISO 8601 timestamp of wake time (when screen turned on)
Sleep duration in hours (clipped to 19:00-07:00 window)
Sleep quality rating (1-5 stars). Auto-assigned based on duration:
- Less than 6h: 2 stars
- 6-8h: 4 stars
- More than 8h: 5 stars
Data relationships
Key conventions
Foreign keys
All daily data boxes useuserId (the user’s email) as a foreign key to relate data back to the user.
Composite keys
Daily records use the pattern{userId}_{YYYY-MM-DD} to ensure:
- Unique keys per user per day
- O(1) lookups for specific dates
- No data collisions between users
Date formatting
Always use ISO 8601 format for timestamps:Type conversions
Hive stores data as maps with dynamic values. Always validate types when reading:Hydration goal calculation
The hydration goal is calculated automatically ifmetaHydratationMl is not set:
- Base:
weight × 35ml - Age less than 14: -10%
- Age 65+: -5%
- Male: +200ml
- Clamped: 1200-4500ml
Related pages
- Database schema - Learn about Hive box organization
- Adding features - Extend Vitu with new tracking features
- Architecture - Understand the overall app structure