flutter_config_plus 1.1.1 copy "flutter_config_plus: ^1.1.1" to clipboard
flutter_config_plus: ^1.1.1 copied to clipboard

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.

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
copied to clipboard

load all environment varibles in main.dart

import 'package:flutter_config_plus/flutter_config_plus.dart';

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

  runApp(MyApp());
}
copied to clipboard

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

import 'package:flutter_config_plus/flutter_config.dart';

FlutterConfigPlus.get('FABRIC_ID') // returns 'abcdefgh'
copied to clipboard

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_plus
copied to clipboard

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

flutter_config_plus.FlutterConfigPlusPlugin.env(for: "ENV_API_KEY")
copied to clipboard

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 FlutterConfigPlus in your tests, simply use the method loadValueForTesting

import 'package:flutter_config_plus/flutter_config_plus.dart';

void main() {
  FlutterConfigPlus.loadValueForTesting({'BASE_URL': 'https://www.mockurl.com'});
  
  test('mock http client test', () {
    final client = HttpClient(
      baseUrl: FlutterConfigPlus.get('BASE_URL')
    );
  });
}
copied to clipboard
13
likes
150
points
1.03k
downloads

Publisher

unverified uploader

Weekly Downloads

2024.07.09 - 2025.01.21

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.

Repository (GitHub)

Documentation

API reference

License

BSD-2-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_config_plus