FLUTTER ECOSYSTEM

ByneappLLC/flutter_config

귀하의 Flutter 앱을 위한 구성 변수.

flutter_config 프로젝트 이미지
Stars
149
Forks
132
최근 푸시(UTC)
2024. 4. 23.
프로젝트 상태
활성
ByneappLLC GitHub avatar
GITHUB Organization

ByneappLLC ↗

언어RubyDartKotlinObjective-C

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 2 개
  • flutter{"sdk":"flutter"}
  • flutter_test개발 의존성{"sdk":"flutter"}

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

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