Skip to content
pubscout

flutter_dotenv

6.0.2, released 6 days ago by an unverified publisher

Loads configuration variables from .env asset files or strings into Flutter apps.

WASM-readyRock solid
$ flutter pub add flutter_dotenv
Source repository

What it does

Loads key-value pairs from `.env` files bundled as Flutter assets or parsed from raw strings. Provides typed getters and fallback options to access non-sensitive configuration values like API URLs and feature flags globally. Supports variable interpolation, overriding files, and programmatic merges.

AI-written summary of version 6.0.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to manage environment-specific configurations (such as base URLs or log levels) across development, staging, and production
  • You want a familiar .env syntax with support for variable interpolation and typed values (int, double, bool)

Skip it when

  • Storing sensitive secrets like private API keys, tokens, or passwords, because asset files are packaged into the app binary and easily extracted

Strengths

  • Built-in typed getters (`getInt`, `getDouble`, `getBool`) with optional fallbacks
  • Supports multiple environment layering via `overrideWithFiles` and programmatic overrides via `mergeWith`
  • Handles variable interpolation (`$BASE_URL/v1` and `${BASE_URL}/v1`) natively

Weaknesses

  • Insecure for confidential secrets since asset files are bundled publicly within client builds
  • Requires `.env` files to be manually registered under the Flutter `assets` section in `pubspec.yaml`

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
0

Requires adding the `.env` file to the `assets` list in `pubspec.yaml`.

import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

Future<void> main() async {
  await dotenv.load(fileName: '.env');
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    final apiUrl = dotenv.get('API_URL', fallback: 'https://default.example.com');
    return MaterialApp(home: Scaffold(body: Center(child: Text(apiUrl))));
  }
}

Alternatives

Packages that do the same job and could replace flutter_dotenv.

  • dotenv

    Load environment variables at runtime from a .env file.

  • flutter_env_native

    Makes --dart-define and --dart-define-from-file variables available to native Android and iOS platforms.

  • cli_config

    Library to read config from CLI args, env vars, and JSON/YAML files

Works with

Packages commonly used together with flutter_dotenv: ones it builds on, ones built on it, and its own family.