# Understanding Flavors

Flavors control how your app loads configuration (Network, Cache, or Local Assets) and which Environment (Dev, Prod) it connects to.

## 1. Concepts

* **Flavor**: Controls the *loading strategy*.
  * **Debug**: Loads from Digia Cloud in real-time. Best for active development.
  * **Staging**: Loads from Digia Cloud but is stable. Best for QA.
  * **Release**: Loads from local assets first (or network if available). Best for App Store builds.
* **Environment**: Controls the *variables* (API endpoints, keys).
  * **Local**: Use local localhost servers.
  * **Development**: Use dev/staging servers.
  * **Production**: Use live production servers.

***

## 2. Configuration

### Debug Flavor (Development)

Use this when you are actively building the app and want to see changes immediately.

{% tabs %}
{% tab title="Flutter" %}

```dart
Flavor.debug(
  environment: Environment.development, // or .local
  branchName: 'feature-x', // Optional: load from specific branch
)
```

{% endtab %}

{% tab title="Android (Jetpack Compose)" %}

```kotlin
Flavor.Debug(
    environment = Environment.Development, // or .Local
    branchName = "feature-x" // Optional
)
```

{% endtab %}
{% endtabs %}

### Staging Flavor (QA/Testing)

Use this for sharing builds with QA or clients.

{% tabs %}
{% tab title="Flutter" %}

```dart
Flavor.staging(
  environment: Environment.production,
)
```

{% endtab %}

{% tab title="Android (Jetpack Compose)" %}

```kotlin
Flavor.Staging(
    environment = Environment.Production
)
```

{% endtab %}
{% endtabs %}

### Release Flavor (Production)

Use this for the final app store build. It requires downloading assets from Digia Studio and bundling them with your app.

**Prerequisite:** Download `app_config.json` and `functions.json` from Digia Studio (Release tab) and place them in your assets folder.

{% tabs %}
{% tab title="Flutter" %}

```dart
Flavor.release(
  initStrategy: NetworkFirstStrategy(timeoutInMs: 3000),
  appConfigPath: 'assets/app_config.json',
  functionsPath: 'assets/functions.json',
)
```

{% endtab %}

{% tab title="Android (Jetpack Compose)" %}

```kotlin
Flavor.Release(
    initStrategy = NetworkFirstStrategy(timeout = 3000),
    appConfigPath = "app_config.json", // in assets/
    functionsPath = "functions.json"   // in assets/
)
```

{% endtab %}
{% endtabs %}

***

## 3. Initialization Strategies

For **Release** flavor, you can choose how the app starts:

* **NetworkFirstStrategy**: Tries to fetch latest config from cloud. Falls back to assets if offline. (Best for most apps).
* **CacheFirstStrategy**: Uses cached config immediately for fastest startup. Updates in background. (Best for e-commerce/content apps).
* **LocalFirstStrategy**: Uses bundled assets only. Never connects to Digia Cloud for config. (Best for completely static apps).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.digia.tech/sdk-integration/sdk-integration/understanding-flavors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
