Giter Club home page Giter Club logo

flutter_config's Introduction

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')
    );
  });
}

flutter_config's People

Contributors

edtheguy00 avatar byneapp avatar pecostef avatar bengmiles avatar beilly avatar cchamm avatar danielgomezrico avatar quango2304 avatar phil-flyclops avatar stefanoventiventures avatar xal avatar hooshyar avatar lordvcs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.