搜索插件、代码仓与 APP 分类

插件详情v4.2.0

dotenv

从 `.env` 文件加载环境变量。

AndroidiOSmacOSWindowsLinux
近 30 天下载
15万
喜欢数
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 项

源码仓库

使用此插件的项目