talira

flutter_dotenv

Load configuration into a Flutter app from a .env file

open sourceMITfree

Forked from dotenv (Dart).

flutter_dotenv loads configuration into a Flutter app from a .env file bundled as an asset, or from a string. After dotenv.load() you read values anywhere with typed getters and fallbacks, and it supports variable interpolation, quoting rules, override files, programmatic values merged on top and, where dart:io is available, system environment variables. Values end up inside the app binary, so it's for public client-side configuration, not secrets. It began as a fork of the dotenv package for Dart.

Problems it solves

  • keep API URLs and feature flags for my Flutter app in a .env file
  • switch Flutter app configuration between staging and production
  • read environment variables in a Flutter app like dotenv does elsewhere

Features

  • load a .env asset or a string at startup
  • typed getters (int, bool, double) with fallbacks
  • variable interpolation with double quotes, none with single quotes
  • override files and programmatic values merged with set precedence
  • merge system environment variables where dart:io is available

Limitations

  • Values are bundled into the app binary and can be extracted, so it must not hold secrets such as API keys or tokens.1

Alternatives

The same job

These do what flutter_dotenv does.

  1. dotenv (Dart) Load environment variables at runtime from a .env file in Dart

Compare flutter_dotenv with the top 3