> For the complete documentation index, see [llms.txt](https://playing-with-flutter.gitbook.io/flutter-production-flavor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://playing-with-flutter.gitbook.io/flutter-production-flavor/config-build-flavor-on-ios.md).

# Config Build Flavor on IOS

Create a build flavor with the name: Nightly

1. Click on the Runner, click the + button, choose duplicate "Debug Configuration", and change the name to "Debug-Nightly".

![](https://874539744-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fj5JEDYzyNYZKBOeD7mDC%2Fuploads%2F50MmCwsqH2JT4WPd8Sr5%2FScreenshot%202023-03-17%20at%2011.09.20.png?alt=media\&token=7ff4418f-f6ce-41e6-a502-2f171af0056d)![](https://874539744-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fj5JEDYzyNYZKBOeD7mDC%2Fuploads%2FmxR4SKzXuQJehxLT5Nfl%2FScreenshot%202023-03-17%20at%2011.09.54.png?alt=media\&token=8f8f8a48-8b09-4111-8dbe-6749c72a17b0)

2. Create New Scheme, named "Nightly" with "target Runner". After that edit scheme with "Build Configuration" in "run, test, analyze" to "Debug-Nightly".![](https://874539744-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fj5JEDYzyNYZKBOeD7mDC%2Fuploads%2F5VHafWZj2v4pYM9WpBti%2FScreenshot%202023-03-17%20at%2011.10.09.png?alt=media\&token=845e0e9e-fcd8-434b-b4a6-ffe154a3b946)![](https://874539744-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fj5JEDYzyNYZKBOeD7mDC%2Fuploads%2FRfxQe5cLnaYaigMVmwcz%2FScreenshot%202023-03-17%20at%2011.10.30.png?alt=media\&token=efa1760f-1ccd-4227-9c91-50623c925bef)![](https://874539744-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fj5JEDYzyNYZKBOeD7mDC%2Fuploads%2FUiFd6ytoOIEEt30lGaf5%2FScreenshot%202023-03-17%20at%2011.12.26.png?alt=media\&token=5f9d2ec1-5b98-4ac0-a506-00bf66799b30)
3. Change "Product bundle identifier" and "Product name" for every flavor.

![](https://874539744-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fj5JEDYzyNYZKBOeD7mDC%2Fuploads%2FuCSAKPmyllhSBLDZ3gRQ%2FScreenshot%202023-03-18%20at%2009.19.18.png?alt=media\&token=ace8ea76-9289-4a7b-89e1-73131adbfa88)![](https://874539744-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fj5JEDYzyNYZKBOeD7mDC%2Fuploads%2FYuUdqCGgsmw5tBh0r6fV%2FScreenshot%202023-03-18%20at%2009.24.27.png?alt=media\&token=7cc85d87-72fa-4589-8aad-31780cbd904a)

4. With another variable like the "Google map API" key. Define a variable in user-defined, and change the value for each flavor

![](https://874539744-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fj5JEDYzyNYZKBOeD7mDC%2Fuploads%2Fdy7VKtYjs8Q36h2mt2Ji%2FScreenshot%202023-03-17%20at%2011.28.27.png?alt=media\&token=6754d4f2-4d9d-4ea5-93c0-62b64ae9dda5)

## Add a file for each environment

an example is add GoogleService-Info.plist&#x20;

1. Copy to project file like this:&#x20;

![](https://874539744-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fj5JEDYzyNYZKBOeD7mDC%2Fuploads%2FvSWKdviqmn9QkeBr1HyD%2FScreenshot%202023-03-18%20at%2009.41.34.png?alt=media\&token=6e046e6b-e78c-486e-9b2a-c7f5e950eed3)

2. Select target Runner, and tab Build Phases, click + button, edit the name of the script to what you want.&#x20;

![](https://874539744-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fj5JEDYzyNYZKBOeD7mDC%2Fuploads%2FbuYLjhNnNkfEemXeEOH8%2FScreenshot%202023-03-18%20at%2009.44.25.png?alt=media\&token=340ceac1-d477-49d5-93fe-070f9bc0aebb)

3. This script means copying the file to the right path when we build with a flavor.

<pre class="language-bash" data-overflow="wrap"><code class="lang-bash">the # Type a script or drag a script file from your workspace to insert its path.

environment="Nightly"

# Regex to extract the scheme name from the Build Configuration
# We have named our Build Configurations as <a data-footnote-ref href="#user-content-fn-1">Debug-Nightly, Debug-Staging, Debug-Production</a> etc.
# Here, Nightly and Staging, Production are the scheme names. This kind of naming is required by Flutter for flavors to work.
# We are using the $CONFIGURATION variable available in the XCode build environment to extract 
# the environment (or flavor)
# For eg.
# If CONFIGURATION="Debug-Nightly", then environment will get set to "<a data-footnote-ref href="#user-content-fn-1">Nightly</a>".
if [[ $CONFIGURATION =~ -([^-]*)$ ]]; then
  environment=${BASH_REMATCH[1]}
fi

echo $environment

# Name and path of the resource we're copying
GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
GOOGLESERVICE_INFO_FILE=${PROJECT_DIR}/config/${environment}/${GOOGLESERVICE_INFO_PLIST}

# Make sure GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_FILE}"
if [ ! -f $GOOGLESERVICE_INFO_FILE ]
then
  echo "No GoogleService-Info.plist found. Please ensure it's in the proper directory."
  exit 1
fi

# Get a reference to the destination location for the GoogleService-Info.plist
# This is the default location where Firebase init code expects to find GoogleServices-Info.plist file
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
echo "Will copy ${GOOGLESERVICE_INFO_PLIST} to final destination: ${PLIST_DESTINATION}"

# Copy over the prod GoogleService-Info.plist for Release builds
cp "${GOOGLESERVICE_INFO_FILE}" "${PLIST_DESTINATION}"
</code></pre>

Change FLUTTER\_TARGET in User-Defined for each environment.&#x20;

**staging**: lib/main\_stg.dart\
**nightly**: lib/main\_nightly.dart\
**production**: lib/main\_production.dart

&#x20;

That's all you need to do.

[^1]:
