ENVSetup class

Load and parse public environment configuration across Flutter platforms.

These examples work in the browser. loadAsset requires a declared Flutter asset; loadFile is native-only. Client assets and bundled configuration are public, never secret storage.

Gallery walkthrough · browser route /#/environment. These examples use the current checkout; published 1.x APIs can differ.

Parse typed public settings

import 'package:activity/activity.dart';

void main() {
  final env = ENVSetup();
  env.loadString('PAGE_SIZE=20\nENABLED=true');
  assert(env.getInt('PAGE_SIZE') == 20);
  assert(env.getBool('ENABLED'));
}

Merge settings with defaults

import 'package:activity/activity.dart';

void main() {
  final env = ENVSetup();
  env.merge({'API_ORIGIN': 'https://example.com'});
  assert(env.getString('API_ORIGIN') == 'https://example.com');
  assert(env.getInt('MISSING_LIMIT', defaultValue: 10) == 10);
}

Constructors

ENVSetup({EnvLogger? logger})

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
values → Map<String, String>
Returns an unmodifiable snapshot of the current environment.
no setter

Methods

clear() → void
Clears all loaded values.
getBool(String key, {bool? defaultValue}) → bool
getDouble(String key, {double? defaultValue}) → double
getDuration(String key, {Duration? defaultValue}) → Duration
getInt(String key, {int? defaultValue}) → int
getString(String key, {String? defaultValue, bool trim = true}) → String
getUri(String key, {Uri? defaultValue}) → Uri
loadAsset(String assetPath, {bool overrideExisting = true, bool expand = true}) → Future<void>
Load from a bundled Flutter asset (works on all platforms, incl. Web).
loadFile(String filePath, {bool overrideExisting = true, bool expand = true}) → Future<void>
Load from a .env file path (mobile/desktop/CLI only).
loadString(String contents, {bool overrideExisting = true, bool expand = true}) → void
Load configuration text directly, useful for tests and remote config.
merge(Map<String, String> entries, {bool overrideExisting = true, bool expand = true}) → void
Merge a map of env values (e.g., from CI secrets or overrides).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited