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

套件詳情v4.2.0

dotenv

從 `.env` 檔案載入環境變數。

AndroidiOSmacOSWindowsLinux
近 30 天下載
16萬
喜歡數
154
Pub 分數
135

安裝套件

flutter pub add dotenv

套件介紹

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

dotenv 套件讓 Flutter 應用程式能夠從 .env 檔案載入環境變數,簡化了在不同環境中進行設定管理。它會從檔案讀取鍵值對,並在應用程式中使其可存取,透過避免硬編碼憑證來提升安全性。這對於管理 API 金鑰、URL 及其他敏感或環境特定的設定特別有用。此套件支援所有主要平台,包括 Android、iOS、macOS、Windows 和 Linux。

適用情境

  • 安全地管理 API 金鑰
  • 按環境配置應用行為
  • 儲存敏感憑證
  • 啟用多環境設定
  • 避免硬編碼配置值

主要特色

  • 從 .env 檔案載入變數
  • 支援平台無關的設定
  • 簡單的鍵值對語法
  • 輕鬆整合至Flutter應用
  • 安全處理機密資訊

適合對象

  • 開發與預發佈環境
  • 需要多個設定檔的應用程式
  • 管理共用設定的團隊
  • 具有嚴格安全需求的專案
  • 使用環境檔案的 CI/CD 流水線

使用建議

  • 永遠不要將 .env 檔案提交到版本控制中
  • 確保將 `.env` 加入 .gitignore
  • 變數僅在啟動時載入
  • 僅限簡單字串值
  • 不適用於複雜的資料結構

原始 README

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

dotenv

Load environment variables at runtime from a .env file.

Pub Version Build Status Documentation style: tidy

about

Deploying applications should be simple. This implies constraints:

The twelve-factor app stores config in environment variables (often shortened to env vars or env). Env vars are easy to change between deploys without changing any code... they are a language- and OS-agnostic standard.

An environment is the set of variables known to a process (say, PATH, PORT, ...). It is desirable to mimic the production environment during development (testing, staging, ...) by reading these values from a file.

This library parses that file and optionally merges its values with the built-in Platform.environment map.

usage

See documentation and examples.

cli

Get the latest:

$ dart pub global activate dotenv

Run:

$ dart pub global run dotenv:new  # create a .env file and add it to .gitignore
$ dart pub global run dotenv      # load the file and print only the file environment variables to stdout
$ dart pub global run dotenv -p   # load the file and print all the environment variables to stdout
discussion

Use the issue tracker for bug reports and feature requests.

Pull requests gleefully considered.

prior art
license: MIT

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案