Environment Variables

Environment variables are crucial for managing different configurations in your project. This guide will help you set up and manage environment variables in your Flutter project.

Overview

Environment variables are used to configure settings and manage sensitive information such as API keys and configuration options. In Flutter, you can use environment variables to keep this information separate from your codebase and manage it securely.

Setting Up Environment Variables

Android and iOS

  1. Configure API base URL in lib/core/constants/app_constants.dart:
    static const String apiBaseUrl = 'https://your-api-url.com/api/v1';
  2. Clone the project and fetch packages:
    flutter pub get
  3. Run the app:
    flutter run

Best Practices

  • Update app_constants.dart file first: Always update app_constants.dart before using environment variables.
  • Use default values: Provide default values for environment variables in case they are not set.
  • Organize variables: Group related environment variables together to improve readability.

Common Issues

  • Environment variables not loading: Make sure the app_constants.dart file is correctly set up and loaded in your Flutter project.
  • Incorrect variable names: Double-check the keys you use to access environment variables match those defined in your app_constants.dart file.