# logiit_flutter

## PR / Release checklist (standard for each new PR)

For every new PR:

1. **Bump the build number** in `pubspec.yaml`: increment the number after the `+` (e.g. `1.4.0+101` → `1.4.0+102`). Do not skip numbers; use the next sequential build.
2. **Add a changelog entry** in `CHANGELOG.md` under `[Unreleased]` (or under a new version section when releasing), briefly describing the changes.

---

## Local Development Test Accounts

When running with the local Docker backend (`--flavor dev`), use these test accounts:

| Role | Email | Password |
|------|-------|----------|
| Diver | diver@logiit.co | password123 |
| Supervisor | supervisor@logiit.co | password123 |
| ROV Pilot | rovpilot@logiit.co | password123 |
| ROV Supervisor | rovsupervisor@logiit.co | password123 |

All accounts have:
- Email verified
- KYC status: APPROVED
- Subscription active until 2027
- South African passport

---

Steps to create a new Model and Service: 
 - create a local and cloud model
 - create a service for the model
 - update the localDb
 - update the action log
 - update the sync service
 - generate g files for models

Steps to create a new Model and Service: (Example using Profile)
 - in lib/models create new folder and Model dart file (profile/profile.dart)
 - in lib/models_isar create new folder and LocalModel dart file (local_profile/local_profile_isar.dart)
 - in lib/services create new service dart file (profile_service.dart)
 - copy over one of the other model_services and replace with relevant models
 - in the local_database_provider.dart file add the new Schema to the list
 - in the action_log_isar.dart file add the new DataType to the enum 
 - in the action_log_isar.dart file update the ActionLog class with the ModelData (ProfileData) type
 - in the action_log_isar.dart file add the new @embedded ModelData (ProfileData) class
 - in the sync_service.dart file add the service to the serviceMap
 - g files are generated with: 'flutter pub run build_runner build'

Your new Model and Service are now ready to be used in the application.

 - We now have the ability to save Offline and Online Models
 - If you are online we save it to the cloud and to the localDb
 - If you are offline we save it to the ActionLogs in the localDb
 - When we come back online again the sync_service runs
 - It loops through all the ActionLogs and performs the actions

# Logging

The app uses a centralized `LoggerService` for all logging operations. **Never use `print()` statements** - they may leak sensitive data in production.

## LoggerService Usage

```dart
import 'package:logiit_flutter/services/services.dart';

// Debug logs (detailed debugging information)
LoggerService().debug('🔄 Getting user', tag: 'AuthService');

// Info logs (general informational messages)
LoggerService().info('User logged in successfully', tag: 'AuthService');

// Warning logs (warnings that don't prevent operation)
LoggerService().warning('API key not configured', tag: 'ConfigService');

// Error logs (errors and exceptions)
LoggerService().error('Failed to sync data', error: e, stackTrace: stack, tag: 'SyncService');
```

## Security Features

- **Build Mode Awareness**: Only logs in debug/profile modes, completely silent in release/production
- **Automatic Sanitization**: Automatically redacts sensitive data:
  - Email addresses
  - JWT tokens
  - API keys
  - User IDs
  - User objects
  - File paths in stack traces

## Log Visibility

- **Console**: Logs appear in your terminal/console with `[TagName]` prefix
- **DevTools**: Logs are also sent to Flutter DevTools for advanced filtering by tag or log level

## Best Practices

- Always provide a descriptive `tag` parameter (e.g., service name or class name)
- Use appropriate log levels (debug for detailed info, error for exceptions)
- Never log sensitive data directly - LoggerService will sanitize it automatically

# App Flavors

To run from the command line, use the following commands:

```bash
flutter run --flavor dev --target lib/main_dev.dart
flutter run --flavor staging --target lib/main_staging.dart
flutter run --flavor demo --target lib/main_demo.dart
flutter run --flavor production --target lib/main_production.dart
```

To build the apk from the command line, use the following commands:

```bash
flutter build apk --flavor dev --target lib/main_dev.dart
flutter build apk --flavor demo --target lib/main_demo.dart
flutter build apk --flavor staging --target lib/main_staging.dart
flutter build apk --flavor production --target lib/main_production.dart
```

**For Google Play Store:** To build the AppBundle from the command line, use the following commands:

```bash
flutter build appbundle --flavor dev --target lib/main_dev.dart
flutter build appbundle --flavor demo --target lib/main_demo.dart
flutter build appbundle --flavor staging --target lib/main_staging.dart
flutter build appbundle --flavor production --target lib/main_production.dart
```

**For Apple App Store:**  To build the app for ios from the command line, use the following commands:

```bash
flutter build ios --target lib/main_dev.dart
flutter build ios --target lib/main_demo.dart
flutter build ios --target lib/main_staging.dart
flutter build ios --target lib/main_production.dart
```

```bash
flutter build ipa --target lib/main_dev.dart
flutter build ipa --target lib/main_demo.dart
flutter build ipa --target lib/main_staging.dart
flutter build ipa --target lib/main_production.dart
```