Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Health Tracker App ๐Ÿ“ฑ

A simple Flutter app to track your daily mood, energy levels, and health insights. Works offline and syncs to the cloud when connected.

โœจ Features

  • Daily Mood Tracking - Log your mood throughout the day
  • Energy Level Monitoring - Track your energy levels
  • Health Insights - View trends and analytics
  • Offline Support - Works without internet connection
  • Cloud Sync - Automatically syncs when online
  • PWA Ready - Install as a web app on any device

๐Ÿ“‹ Requirements

System Requirements

  • Flutter SDK: 3.0 or higher
  • Dart SDK: 3.0 or higher
  • Platform: iOS, Android, Web, macOS, Windows, Linux
  • Browser: Chrome (for PWA testing)

External Services

  • Supabase Account: Free account at supabase.com
  • Internet Connection: For initial setup and cloud sync (app works offline)

๐Ÿš€ Quick Start

1. Install Dependencies

flutter pub get

2. Environment Setup

Required Environment Variables: Create a .env file in the project root with the following variables:

# Copy the example file
cp env.example .env

Edit .env file with your credentials:

# Supabase Configuration (Required)
SUPABASE_URL=https://your-project-id.supabase.co
SUPABASE_ANON_KEY=your-anon-key-here

# App Configuration (Optional)
APP_NAME=Health Tracker
APP_VERSION=1.0.0

Where to find Supabase credentials:

  1. Go to supabase.com and create a free account
  2. Create a new project
  3. Go to Project Settings โ†’ API
  4. Copy the "Project URL" and "anon public" key

3. Set Up Database

  1. Open Supabase Dashboard โ†’ SQL Editor
  2. Copy and paste the contents of supabase_quick_setup.sql
  3. Click "Run"

4. Run the App

# Mobile/Desktop
flutter run

# Web (PWA)
flutter run -d chrome --web-port 8080

๐ŸŒ Network Connectivity

The app intelligently handles network connectivity:

โœ… Online Mode

  • Entries sync automatically to Supabase
  • Real-time data backup
  • Full functionality available

๐Ÿ“ฑ Offline Mode

  • All entries saved locally
  • App works completely offline
  • Data syncs when connection returns

๐Ÿ”„ Smart Sync

  • Checks internet connection before syncing
  • Shows clear error messages for network issues
  • Prevents hanging operations when offline

๐ŸŒ Running as PWA (Progressive Web App)

Your Health Tracker app can run as a Progressive Web App in any browser and be installed like a native app!

๐Ÿš€ Quick Start - Run PWA

flutter run -d chrome --web-port 8080
  • Opens in Chrome automatically
  • Hot reload enabled for development
  • Access at: http://localhost:8080

๐Ÿ—๏ธ Project Structure

lib/
โ”œโ”€โ”€ main.dart                    # App entry point
โ”œโ”€โ”€ models/health_entry.dart     # Data model
โ”œโ”€โ”€ services/
โ”‚   โ”œโ”€โ”€ health_service.dart      # Data management
โ”‚   โ””โ”€โ”€ network_service.dart     # Network connectivity
โ”œโ”€โ”€ providers/health_entries_provider.dart  # State management
โ”œโ”€โ”€ pages/
โ”‚   โ”œโ”€โ”€ home_page.dart           # Main entries page
โ”‚   โ””โ”€โ”€ insights_page.dart       # Analytics page
โ””โ”€โ”€ widgets/                     # Reusable UI components

๐Ÿงช Testing

๐Ÿš€ Running Tests

# Run all tests
flutter test

# Run specific test suites
flutter test test/widget/mood_selector_test.dart
flutter test test/widget/energy_level_selector_test.dart
flutter test test/providers/health_entries_provider_test.dart

# Run with coverage
flutter test --coverage

๐Ÿ“‹ Manual Testing Scenarios

๐Ÿ”„ Network Connectivity Testing

Test 1: Online to Offline Transition

  1. Setup: Start app with internet connection
  2. Action: Disable WiFi/mobile data
  3. Expected:
    • Orange banner appears: "No internet connection. Entries are saved locally and will sync when online."
    • App continues to work normally
    • New entries are saved locally
  4. Action: Re-enable internet connection
  5. Expected:
    • Banner disappears automatically
    • Local entries sync to Supabase

Test 2: Offline Entry Creation

  1. Setup: Disconnect from internet
  2. Action: Add a new health entry
  3. Expected:
    • Entry saves successfully
    • Success dialog shows
    • Entry appears in list immediately
    • Entry marked as unsynced (if visible in UI)

Test 3: Sync After Coming Online

  1. Setup: Create entries while offline
  2. Action: Reconnect to internet
  3. Action: Tap sync button (if available) or restart app
  4. Expected:
    • Entries sync to Supabase
    • Success message appears
    • All entries marked as synced

๐Ÿ“ฑ Core Functionality Testing

Test 4: Add Health Entry

  1. Action: Tap the "+" button
  2. Expected: Bottom sheet opens with form
  3. Action: Fill in mood, energy level, optional note
  4. Action: Tap "Save Entry"
  5. Expected:
    • Success dialog appears
    • Entry appears in list
    • Form closes automatically

Test 5: Duplicate Entry Prevention

  1. Setup: Add an entry for "Morning" today
  2. Action: Try to add another entry for "Morning" today
  3. Expected:
    • Error dialog: "You can only add one entry per time of day"
    • Form remains open
    • No duplicate entry created

Test 6: Daily Entry Limit

  1. Setup: Add entries for Morning, Afternoon, Evening
  2. Action: Try to add a 4th entry
  3. Expected:
    • Error dialog: "You can only add 3 entries per day"
    • Form closes
    • No 4th entry created

๐Ÿ”„ Data Sync Testing

Test 7: Bidirectional Sync

  1. Setup: Create entries on Device A, sync to Supabase
  2. Action: Open app on Device B (or clear local data)
  3. Expected:
    • App loads entries from Supabase
    • All entries appear correctly
    • Timestamps preserved

Test 8: Conflict Resolution

  1. Setup: Create same entry on two devices while offline
  2. Action: Sync both devices when online
  3. Expected:
    • Most recent entry wins (based on timestamp)
    • No duplicate entries
    • Sync completes successfully

Test 9: Startup Sync

  1. Setup: Have entries in Supabase that aren't local
  2. Action: Start the app
  3. Expected:
    • App automatically syncs on startup
    • Remote entries appear in local list
    • No user interaction required

๐Ÿ“Š Insights and Analytics Testing

Test 10: Mood Distribution

  1. Setup: Add entries with different moods
  2. Action: Navigate to Insights tab
  3. Expected:
    • Mood distribution chart shows correct counts
    • All moods represented accurately

Test 11: Weekly Trend

  1. Setup: Add entries over multiple days
  2. Action: View Insights page
  3. Expected:
    • Weekly trend chart shows last 7 days
    • Average mood calculated correctly
    • Days without entries show neutral mood

๐Ÿ”ง Error Handling Testing

Test 14: Network Error Recovery

  1. Setup: Start sync operation
  2. Action: Disconnect internet mid-sync
  3. Expected:
    • Clear error message appears
    • App doesn't hang or crash
    • User can retry when online

Test 15: Invalid Data Handling

  1. Action: Try to submit form with missing required fields
  2. Expected:
    • Form validation prevents submission
    • Clear error messages guide user
    • No crashes or unexpected behavior

๐ŸŽฏ Expected Behaviors Summary

โœ… Success Scenarios

  • Entry Creation: Smooth form interaction, immediate local save, cloud sync
  • Offline Mode: Full functionality, clear status indication, automatic sync when online
  • Data Sync: Bidirectional sync, conflict resolution, startup sync
  • PWA: Native app experience, offline support, proper installation

โš ๏ธ Error Scenarios

  • Network Issues: Graceful degradation, clear error messages, retry capability
  • Validation Errors: Form validation, user guidance, no data loss
  • Sync Conflicts: Automatic resolution, data integrity maintained

๐Ÿ”„ Performance Expectations

  • App Startup: < 2 seconds to load
  • Entry Creation: < 1 second to save locally
  • Sync Operations: < 5 seconds for typical data set
  • UI Responsiveness: Smooth animations, no lag

๐Ÿ“Š Test Coverage

Test Results: Run flutter test to see current status

๐Ÿšจ Troubleshooting

Common Issues

"No internet connection" error:

  • Check your network connection
  • The app works offline - entries are saved locally
  • Sync will happen automatically when online

"Could not find table" error:

  • Make sure you ran the Supabase setup SQL script
  • Check that the table exists in Supabase Dashboard

Environment/Setup Issues:

  • "Environment variables not configured": Make sure .env file exists and has correct Supabase credentials
  • "Could not find .env file": Run cp env.example .env and edit with your credentials
  • "Invalid Supabase URL": Check that your URL format is https://your-project-id.supabase.co

Sync failures:

  • Verify your Supabase URL and API key in .env
  • Check internet connection
  • Look at Supabase logs for detailed errors

Getting Help

  1. Check the console for error messages
  2. Verify your .env file has correct Supabase credentials
  3. Ensure you've run the database setup script
  4. Check Supabase Dashboard logs

๐Ÿ“ Assignment Reflection

โฑ๏ธ Time Investment

Total Time: 8 hours

  • Initial setup and basic functionality: 4 hours
  • UI/UX styling and polish: 2 hours
  • Network connectivity and offline support: 1 hour
  • PWA setup and testing: 1 hour

โœจ What I Like About My Implementation

๐ŸŽจ User Experience

  • Clean, intuitive interface with smooth animations
  • Responsive design that works on all screen sizes
  • Clear visual feedback with loading states and error messages
  • Offline-first approach ensures app always works

๐Ÿ—๏ธ Architecture

  • Simple, maintainable code structure without over-engineering
  • Clean separation of concerns (UI, business logic, data)
  • Robust error handling with user-friendly messages
  • Efficient local storage with smart cloud sync

๐Ÿ“ฑ Technical Features

  • Progressive Web App (PWA) support for cross-platform deployment
  • Network connectivity awareness prevents hanging operations
  • Local-first data storage with automatic cloud backup
  • Comprehensive testing coverage for core components

๐Ÿ”ฎ What I Would Change With More Time

๐Ÿ‘ค User Management

  • Add proper user authentication (email/password, Google, Apple)
  • Implement user profiles with personalized settings
  • Add multi-user support with data isolation
  • User-specific mood history and insights

๐Ÿ“Š Enhanced Features

  • Data export/import functionality (CSV, JSON)
  • Advanced analytics with trends and patterns
  • Mood reminders and notifications
  • Social features (share insights, family tracking)

๐Ÿ”ง Technical Improvements

  • Implement proper data validation and sanitization
  • Add comprehensive integration tests
  • Optimize performance for large datasets
  • Add accessibility features (screen reader support)
  • Implement proper conflict resolution for sync

๐ŸŽฏ User Experience

  • Add onboarding flow for new users
  • Implement dark mode theme
  • Add haptic feedback for mobile
  • Create custom mood/energy level options

๐Ÿ—๏ธ Technology Choices Explained

State Management: Provider Pattern

  • Why: Simple, well-documented, and perfect for this app size
  • Benefits: Easy to understand, good performance, built-in Flutter support
  • Alternative: Could use Riverpod or Bloc for larger apps

Storage: SharedPreferences + Supabase

  • Local Storage: SharedPreferences for fast, reliable local data
  • Cloud Storage: Supabase for real-time sync and backup
  • Why This Combo: Offline-first approach with cloud backup
  • Benefits: Works offline, fast local access, automatic sync

Network: Connectivity Plus

  • Why: Prevents hanging operations when offline
  • Benefits: Better user experience, clear error messages
  • Implementation: Smart sync that checks connectivity first

๐Ÿš€ Running Instructions

Quick Start:

# 1. Install dependencies
flutter pub get

# 2. Set up environment
cp env.example .env
# Edit .env with your Supabase credentials

# 3. Set up database
# Run supabase_quick_setup.sql in Supabase Dashboard

# 4. Run the app
flutter run                    # Mobile/Desktop
flutter run -d chrome         # Web/PWA

PWA Installation:

  1. Run flutter run -d chrome --web-port 8080
  2. Open Chrome and go to http://localhost:8080
  3. Click install button in address bar
  4. App installs like a native app! \

About

A Flutter application for tracking daily mood, energy levels, and health insights with cloud synchronization capabilities.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages