Environments

Environments isolate your configuration, data, and users across production, staging, and development — each with its own API keys.

Overview

Every Koolbase project has one or more environments. Each environment is a completely isolated context — it has its own:

API keys (public and secret)
Feature flags and remote config values
Version enforcement policies
Database collections and records
Storage buckets and files
Function deployments
Project users and sessions

Changes made in one environment never affect another. Your production users are always isolated from staging and development activity.

Recommended Setup

Most teams use three environments:

Productionpk_live_...

Live users and real data. Feature flags are carefully controlled. Version enforcement is active. Treat this environment with care.

Stagingpk_live_...

Pre-release testing environment. Mirrors production config but with test data. Use this to validate changes before going live.

Developmentpk_live_...

Local development. All flags can be freely toggled. No real users. Safe to experiment without risk.

API Keys

Each environment has two keys:

pk_live_...Public Key

Used in your Flutter app. Safe to include in client-side code. Used with Koolbase.init().

sk_live_...Secret Key

Used for server-side API calls. Never expose this in client code or commit it to version control.

Key rotation

You can rotate either key from the dashboard at any time. Rotating a key immediately invalidates the old key. All SDK instances using the old key will fail until updated. Plan rotations carefully in production.

Using Environments in Flutter

Pass the correct key for each build flavor using Dart environment variables or a config file:

lib/main.dartDart
import 'package:flutter/material.dart';
import 'package:koolbase/koolbase.dart';

// Define keys per environment
const koolbaseKeys = {
  'production': 'pk_live_prod_key_here',
  'staging':    'pk_live_staging_key_here',
  'development': 'pk_live_dev_key_here',
};

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Use --dart-define=ENV=production to switch environments
  const env = String.fromEnvironment('ENV', defaultValue: 'development');
  final apiKey = koolbaseKeys[env] ?? koolbaseKeys['development']!;

  await Koolbase.init(apiKey: apiKey);
  runApp(const MyApp());
}

Run with a specific environment:

# Development (default)
flutter run

# Staging
flutter run --dart-define=ENV=staging

# Production build
flutter build apk --dart-define=ENV=production

Duplicating Environments

From the dashboard you can duplicate an existing environment. This copies all feature flags, flag rules, remote config values, and version policies into a new environment with fresh API keys.

This is useful when setting up a new staging environment that mirrors your current production config, or when creating a demo environment for testing.

What is not copied

Duplication copies configuration only. Database records, storage files, project users, function deployments, and secrets are not copied to the new environment.