flutter_dotenv_remote

Load remote configuration into flutter_dotenv, with the last successful config cached for offline use.

Use flutterdotenv.com to manage configs, or connect your own Supabase project.

Get started

Requires Flutter 3.35+ and Dart 3.9+.

flutter pub add flutter_dotenv_remote flutter_dotenv

Create and publish a config at flutterdotenv.com, then copy its config ID. Load it before starting your app:

import 'package:flutter/widgets.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_dotenv_remote/flutter_dotenv_remote.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await dotenv.loadRemote(configId: 'your-config-id');

  runApp(const MyApp());
}

Read values using the usual flutter_dotenv API:

final apiUrl = dotenv.get('API_URL');

Fallback

On success, the config is loaded and cached. If the fetch fails after Supabase's configured retries, the cached config is used; if none exists, the default fallback loads .env into the global dotenv instance.

Create a .env file with fallback values and declare it in your app's pubspec.yaml:

flutter:
  assets:
    - .env

Use useCacheOnFailure: false to skip cached values, or supply an asynchronous onLoadFailure callback to replace the .env fallback. Without a cached config or a loadable .env, the default fallback throws.

Your own Supabase project

Your project needs an envs table with an id column and an environment_json column containing a JSON object of environment variables. The client must have permission to read the requested row.

await dotenv.loadRemote(
  configId: 'your-id',
  supabaseConfig: (
    url: 'https://your-project.supabase.co',
    anonKey: 'your-anon-key',
  ),
);

To reuse an existing client, pass supabaseClient: yourClient instead of supabaseConfig. Its authentication, headers, schema, retries, and timeout are retained. The client's settings and lifetime remain under your control.

Security

Remote config and bundled .env files are accessible to app users. Use them for configuration, not private secrets.

Example app · Changelog · Report an issue · License