# logiit_flutter

## Building and Testing

### Prerequisites
- Flutter SDK 3.38.5 (Dart 3.10.0+)
- Android SDK for Android builds
- Xcode for iOS builds (macOS only)

**Note:** This project uses FVM (Flutter Version Management) to pin Flutter SDK version 3.38.5. If you have FVM installed, run `fvm install` to install the specified Flutter version.

### Setup
1. Install dependencies:
```bash
flutter pub get
```

2. Generate code files (Isar models, JSON serialization):
```bash
flutter pub run build_runner build --delete-conflicting-outputs
```

3. Run tests:
```bash
flutter test
```

### Building

**Android APK Build:**
The build configuration automatically uses debug signing when `key.properties` is not present. For production releases, create `android/key.properties` with your signing credentials.

Build release APK:
```bash
flutter build apk --flavor dev --target lib/main_dev.dart
```

Build debug APK (faster, larger):
```bash
flutter build apk --debug --flavor dev --target lib/main_dev.dart
```

**Note:** The build will automatically use debug signing if `android/key.properties` doesn't exist. For production releases, configure proper signing in `android/key.properties`.

### Testing on Emulator

To test the built APK on an Android emulator:

1. Start an emulator:
```bash
flutter emulators --launch <emulator_id>
```

2. Install and run the app:
```bash
flutter run --flavor dev --target lib/main_dev.dart -d <device_id>
```

Or install the APK directly:
```bash
adb install build\app\outputs\flutter-apk\app-dev-release.apk
```

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

# 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
```

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
```

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

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
```