搜尋套件、儲存庫與 APP 分類

套件詳情v2.1.0

env_reader

從 .env 檔案中讀取、加密或產生環境變數,並放入混淆的 Dart 模型中。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
82
喜歡數
23
Pub 分數
140

安裝套件

flutter pub add env_reader

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

env_reader 是一個 Dart 套件,可透過從 .env 檔案讀取、加密或產生環境變數來實現安全處理。它將這些變數轉換為混淆的 Dart 模型,透過防止敏感資料暴露來增強安全性。適用於多個平台,支援 Android、iOS、Web、macOS、Windows 和 Linux。可透過簡單的 pub add 命令無縫整合至 Flutter 項目中。非常適合重視生產與開發環境中設定安全性的開發者。

適用情境

  • 安全地管理 API 金鑰
  • 保護資料庫憑據
  • 在CI/CD流水線中處理應用密鑰
  • 啟用加密設定檔
  • 安全共享環境設定
  • 自動化環境變數生成

主要特色

  • 安全讀取 .env 檔案
  • 加密環境變數
  • 產生混淆的 Dart 模型
  • 支援多平台部署
  • 透過 pub 提供輕鬆整合
  • 提供加密和解密工具

適合對象

  • 專注於應用安全的開發人員
  • 使用基於環境的設定
  • 需要密鑰管理的項目
  • 包含敏感數據的 Flutter 應用
  • 需要安全環境處理的 CI/CD 工作流
  • 跨多個平台部署的應用程式

使用建議

  • 需要妥善的加密密鑰管理
  • 初始設定涉及配置步驟
  • 混淆無法取代完整加密
  • 不適合高度動態的執行時間金鑰
  • 依賴外部 .env 檔案的存有
  • 可能需要額外的建構過程步驟

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。


Env Reader

Read, encrypt, or generate environment variables from .env file into an obfuscated Dart model.

Features 🚀

  • Automated Generation: Transform your .env files into dynamic Dart models directly. No need to add annotation. ✨
  • Seamless Integration: Directly update your pubspec.yaml and .gitignore on command. No need manual labor. 🛠️
  • Fortified Encryption: Shield your precious .env configurations with an encryption. Say no to prying eyes.🔒
  • Data Diversity Unleashed: Whether they're integers, decimals, booleans, or strings. Automatic interpretation is at your service. 🎮
  • Versatile Sourcing: Load your .env from various sources: assets, files, memory, network, and strings. The choice is yours. 🔄

Install 🚀

Get started with these quick commands:

🔥 Add env_reader to your pubspec.yaml with a single line:

dart pub add env_reader

✨ Unlock the magic by activating the env_reader CLI:

dart pub global activate env_reader

Usage 🚀

Now elevate your development experience with these straightforward steps:

1. Set up your configuration

Start by crafting your .env file in the root directory of your project, right alongside your trusty pubspec.yaml.

API_KEY=VYIUJ7tLdJFqrBesnOJEpkbceBB5GNz0t1aYgHxK3BMxbJOc/g==
DEBUG=true
PORT=8080
DATABASE_URL=postgresql://user:password@localhost:5432/mydb

2. Run the command (Optional)

Now, if you want to generate encrypted env file, run this command in your terminal:

env_reader --input=".env" --output="assets/env/" --key="MyOptionalSecretKey"

[!NOTE] output: .env successfully encrypted into assets/env/.env 🚀

also if you want to generate dart model from this env file, use tihs:

env_reader --input-".env" --model="lib/src/env_model.dart" --null-safety

[!NOTE] output: .env successfully generated into lib/src/env_model.dart 🎉


3. Loading your .env

Load the env_reader instance:

import 'package:env_reader/env_reader.dart';
import 'package:flutter/services.dart';

await Env.load(
  EnvStringLoader(await rootBundle.loadString('assets/env/.env')),
  "MyOptionalSecretKey");

// Or you can load by creating your own `EnvReader` instance.

EnvReader production = EnvReader();
await production.load(
  EnvStringLoader(await rootBundle.loadString('assets/env/.env')),
  "MyOptionalSecretKey");

4. Access your configuration

To get and read the value of your env:

import 'package:env_reader/env_reader.dart';
import 'package:my_package/src/env_model.dart';

String api = Env.read("API_KEY") ?? "Got'cha 😎";
bool debug = Env.read<bool>("DEBUG") ?? false;

// If you make your own instance, call it like this

String api = production.read("API_KEY") ?? "Got'cha 😎";
bool debug = production.read<bool>("DEBUG") ?? false;

Text(
  text:
    debug ? "🤫 pssst, this is my api key y'all \n\n $api" : "Nothing to see here 🤪",
);

// Or you can access the value directly from env generated model earlier

Text(
  text:
    EnvModel.debug ? "🤫 pssst, this is my api key y'all \n\n ${EnvModel.apiKey}" : "Nothing to see here 🤪",
);

Env Reader Command 🚀

Available commands:

Flag Description
-i, --input (mandatory) Input path of the .env file
-o, --output Output path for the encrypted .env file
-s, --key Secrey key for encryption & decryption
--model Generate dart model file to your desired file path
--null-safety Make the model null safety
--[no-]obfuscate Obfuscating generated values of model
(defaults to on)
--[no-]pubspec Insert asset path to pubspec.yaml
(defaults to on)
--[no-]gitignore Insert .env input & output file into .gitignore
(defaults to on)
-h, --help Print usage information

Example usage:

env_reader -i ".env" -o "assets/env/" -s "MyOptionalSecretKey" --model="lib/src/env_model.dart" --null-safety

Example 🚀

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。