Search packages, repositories and app categories

Package detailsv2.0.2

flutter_config

Plugin that exposes environment variables to your Dart code in Flutter as well as to your native code in iOS and Android. Bring some 12 factor love to your Flutter apps

AndroidiOS
30-day downloads
2.7K
Likes
211
Pub points
140

Install package

flutter pub add flutter_config

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

flutter_config is a Flutter plugin that enables seamless access to environment variables in both Dart and native code for Android and iOS. It brings 12-factor app principles to Flutter by allowing developers to manage configuration externally, improving security and flexibility across different environments like development, staging, and production. The package reads configuration from platform-specific files (e.g., info.plist on iOS, build.gradle on Android) and exposes them as constants in Dart. This helps avoid hardcoding sensitive values and simplifies deployment workflows.

Use cases

  • Managing API endpoints per environment
  • Storing API keys securely
  • Switching between dev/staging/prod configurations
  • Customizing app behavior based on environment
  • Enabling feature flags via config
  • Sharing config with native code

Key features

  • Supports Android and iOS platforms
  • Reads config from native project files
  • Exposes variables to Dart and native code
  • Follows 12-factor app methodology
  • Easy integration via pub add
  • No runtime overhead

Suitable for

  • Developers using multiple environments
  • Teams needing secure config management
  • Apps requiring native code access to config
  • Projects following 12-factor principles
  • CI/CD pipelines with environment-specific settings
  • Apps with dynamic feature toggles

Considerations

  • Config must be set before app starts
  • Sensitive data should not be committed to version control
  • Requires manual setup in native projects
  • Not suitable for runtime configuration changes
  • Limited to static values at build time
  • Needs proper documentation for team onboarding

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Config Variables for your Flutter apps

Plugin that exposes environment variables to your Dart code in Flutter as well as to your native code in iOS and Android.

Inspired by react-native-config

Basic Usage

Create a new file .env in the root of your Flutter app:

API_URL=https://myapi.com
FABRIC_ID=abcdefgh

load all environment varibles in main.dart

import 'package:flutter_config/flutter_config.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized(); // Required by FlutterConfig
  await FlutterConfig.loadEnvVariables();

  runApp(MyApp());
}

Now you can access your environment varibles anywhere in your app.

import 'package:flutter_config/flutter_config.dart';

FlutterConfig.get('FABRIC_ID') // returns 'abcdefgh'

Keep in mind this module doesn't obfuscate or encrypt secrets for packaging, so do not store sensitive keys in .env. It's basically impossible to prevent users from reverse engineering mobile app secrets, so design your app (and APIs) with that in mind.


Load Environment Varibles in Swift

First import the plugin

import flutter_config

Then you can use the .env Variable, replace ENV_API_KEY with yours.

flutter_config.FlutterConfigPlugin.env(for: "ENV_API_KEY")

Getting Started

Install the latest version of the plugin

Refer to Android Setup Guide for initial setup and advanced options

No additional setup is required for iOS, however, for advanced usage refer to the iOS Setup Guide

Testing

Whenever you need to use FlutterConfig in your tests, simply use the method loadValueForTesting

import 'package:flutter_config/flutter_config.dart';

void main() {
  FlutterConfig.loadValueForTesting({'BASE_URL': 'https://www.mockurl.com'});
  
  test('mock http client test', () {
    final client = HttpClient(
      baseUrl: FlutterConfig.get('BASE_URL')
    );
  });
}

Categories

Source repository

Projects using this package