<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nguyễn Hưng</title>
    <description>The latest articles on DEV Community by Nguyễn Hưng (@hunnguydev101).</description>
    <link>https://dev.to/hunnguydev101</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2712512%2F7a55103d-dec2-4a90-ba6d-ee2494ca4137.jpg</url>
      <title>DEV Community: Nguyễn Hưng</title>
      <link>https://dev.to/hunnguydev101</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hunnguydev101"/>
    <language>en</language>
    <item>
      <title>Mastering Flavors in Flutter: A Step-by-Step Approach</title>
      <dc:creator>Nguyễn Hưng</dc:creator>
      <pubDate>Tue, 04 Mar 2025 03:10:49 +0000</pubDate>
      <link>https://dev.to/hunnguydev101/mastering-flavors-in-flutter-a-step-by-step-approach-1en3</link>
      <guid>https://dev.to/hunnguydev101/mastering-flavors-in-flutter-a-step-by-step-approach-1en3</guid>
      <description>&lt;p&gt;When developing Flutter applications, managing different configurations for development, staging, and production environments can be challenging. &lt;/p&gt;

&lt;p&gt;This is where flavors come in handy. By using a package like &lt;a href="https://pub.dev/packages/flutter_flavorizr" rel="noopener noreferrer"&gt;flutter_flavorizr&lt;/a&gt;, you can streamline the process of creating and managing flavors in your Flutter app. &lt;/p&gt;

&lt;p&gt;Here's a detailed guide to help you get started!&lt;/p&gt;




&lt;h2&gt;
  
  
  What are Flavors in Flutter?
&lt;/h2&gt;

&lt;p&gt;Flavors mean you define multiple build configurations within the same codebase. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Development (dev): Used for internal testing and debugging.&lt;/li&gt;
&lt;li&gt;Staging (staging): Pre-production testing for QA teams.&lt;/li&gt;
&lt;li&gt;Production (prod): The final build for end-users.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each flavor can have its unique settings, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;App name and icon.&lt;/li&gt;
&lt;li&gt;Firebase configurations.&lt;/li&gt;
&lt;li&gt;API endpoints and environment variables.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why use flutter_flavorizr?
&lt;/h2&gt;

&lt;p&gt;Manually setting up flavors can be time-consuming and error-prone as it requires changes across multiple files in both Android and iOS projects. &lt;/p&gt;

&lt;p&gt;The &lt;a href="https://pub.dev/packages/flutter_flavorizr" rel="noopener noreferrer"&gt;flutter_flavorizr&lt;/a&gt; package automates this process by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generating flavor-specific configurations.&lt;/li&gt;
&lt;li&gt;Managing Android and iOS settings for each flavor.&lt;/li&gt;
&lt;li&gt;Reducing manual overhead and potential errors.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Add the Package:&lt;/strong&gt; Add &lt;a href="https://pub.dev/packages/flutter_flavorizr" rel="noopener noreferrer"&gt;flutter_flavorizr&lt;/a&gt; to your dev_dependencies in pubspec.yaml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dev_dependencies:
  flutter_flavorizr: ^2.2.3 # Latest version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Define Flavors&lt;/strong&gt;: Create a &lt;code&gt;flavorizr.yaml&lt;/code&gt; file in the root of your project. And then add some configuration&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app:
  android:
    flavorDimensions: "app"
flavors:
  dev:
    app:
      name: "AppFlavor Dev"
    android:
      applicationId: "com.urcompany.android.dev"
      icon: "assets/icon_app/android/icon_app.png"
    ios:
      bundleId: "com.urcompany.ios.dev"
      icon: "assets/icon_app/ios/icon_app.png"
  stg:
    app:
      name: "AppFlavor Stg"
    android:
      applicationId: "com.urcompany.android.stg"
      icon: "assets/icon_app/android/icon_app.png"
    ios:
      bundleId: "com.urcompany.ios.stg"
      icon: "assets/icon_app/ios/icon_app.png"
  prod:
    app:
      name: "AppFlavor"
    android:
      applicationId: "com.urcompany.android"
      icon: "assets/icon_app/android/icon_app.png"
    ios:
      bundleId: "com.urcompany.ios"
      icon: "assets/icon_app/ios/icon_app.png"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Generate Configurations&lt;/strong&gt;: Run the generator command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flutter pub run flutter_flavorizr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running this, the library will create and modify some files in your project to fit your configuration.&lt;/p&gt;

&lt;p&gt;Once the process is complete, you will be able to launch your Flutter flavors.&lt;/p&gt;

&lt;p&gt;Now, you can run your app in different environments with the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;run-app:
  dev:
    - flutter run --flavor dev -t lib/main_dev.dart
  prod:
    - flutter run --flavor prod -t lib/main_prod.dart
  stg:
    - flutter run --flavor stg -t lib/main_stg.dart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumch7ewchpyf4dkc7mag.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumch7ewchpyf4dkc7mag.png" width="750" height="1334"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Firebase config with flavor
&lt;/h3&gt;

&lt;p&gt;flutter_flavorizr allows you to configure Firebase settings for each environment. &lt;/p&gt;

&lt;p&gt;Here’s an update of how you can define Firebase configurations in flavorizr.yaml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app:
  android:
    flavorDimensions: "app"
flavors:
  dev:
    app:
      name: "AppFlavor Dev"
    android:
      applicationId: "com.urcompany.android.dev"
      icon: "assets/icon_app/android/icon_app.png"
      firebase:
        config: ".firebase/android/google-services-dev.json"
    ios:
      bundleId: "com.urcompany.ios.dev"
      icon: "assets/icon_app/ios/icon_app.png"
      firebase:
        config: ".firebase/ios/GoogleService-Info-dev.plist"
  stg:
    app:
      name: "AppFlavor Stg"
    android:
      applicationId: "com.urcompany.android.stg"
      icon: "assets/icon_app/android/icon_app.png"
      firebase:
        config: ".firebase/android/google-services-stg.json"
    ios:
      bundleId: "com.urcompany.ios.stg"
      icon: "assets/icon_app/ios/icon_app.png"
      firebase:
        config: ".firebase/ios/GoogleService-Info-stg.plist"
  prod:
    app:
      name: "AppFlavor"
    android:
      applicationId: "com.urcompany.android"
      icon: "assets/icon_app/android/icon_app.png"
      firebase:
        config: ".firebase/android/google-services.json"
    ios:
      bundleId: "com.urcompany.ios"
      icon: "assets/icon_app/ios/icon_app.png"
      firebase:
        config: ".firebase/ios/GoogleService-Info.plist"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After defining the Firebase configurations, run the following command to generate the correct Firebase setup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dart run flutter_flavorizr -p google:firebase
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, each environment will point to its respective Firebase configuration.&lt;/p&gt;

&lt;p&gt;For more details and advanced configurations, check out the official &lt;a href="https://pub.dev/packages/flutter_flavorizr" rel="noopener noreferrer"&gt;flutter_flavorizr&lt;/a&gt; documentation.&lt;/p&gt;

&lt;p&gt;By leveraging flutter_flavorizr, you can streamline your development process and ensure a well-organized, scalable app structure. Happy coding!&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>mobile</category>
    </item>
  </channel>
</rss>
