← Back to posts Cover image for Mastering Flutter Remote Config: Beyond Firebase for Dynamic App Updates

Mastering Flutter Remote Config: Beyond Firebase for Dynamic App Updates

· 5 min read
Weekly Digest

The Flutter news you actually need

No spam, ever. Unsubscribe in one click.

Chris
By Chris

Firebase Remote Config is often the first answer when Flutter apps need dynamic behavior. If you already use Firebase, it can be a solid choice. But it is not always the right fit. Some teams want to avoid vendor lock-in, reduce SDK weight, keep configuration on their own infrastructure, or stay within stricter privacy or compliance boundaries.

Remote configuration in Flutter does not require Firebase. You can build a dependable system with a simple HTTP endpoint, a JSON document, and — most importantly — validation that rejects bad payloads before they change app behavior.

The real problem: remote JSON is production input

A common mistake is treating a remote config endpoint like a trusted source of truth. Developers fetch JSON, decode it, and pass it directly into widgets:

final config = jsonDecode(response.body) as Map<String, dynamic>;

if (config['features']['new_checkout']) {
  // ...
}

This looks harmless until someone publishes a malformed payload. A boolean becomes a string. A required key disappears. A number turns into null. Now your app either crashes on startup or silently changes behavior in ways no one reviewed.

Remote config is not just data. It is a deployable contract. If you would not deploy unreviewed code, you should not deploy unvalidated configuration.

A safer pattern: fetch, validate, swap, cache

A robust Flutter remote config flow has four responsibilities:

  1. Fetch a versioned JSON document.
  2. Validate it against a schema before applying it.
  3. Atomically replace the current config with the new one.
  4. Fall back to the last known good config if validation or network fails.

For example, your endpoint might serve:

{
  "version": "1.2.0",
  "features": {
    "new_checkout": true
  },
  "limits": {
    "retry_attempts": 3
  }
}

In Dart, you can define a schema that rejects payloads with missing fields, wrong types, or invalid values.

import 'package:json_schema/json_schema.dart';

final appConfigSchema = JsonSchema.create({
  "type": "object",
  "required": ["version", "features", "limits"],
  "properties": {
    "version": {
      "type": "string",
      "pattern": r"^\d+\.\d+\.\d+$"
    },
    "features": {
      "type": "object",
      "required": ["new_checkout"],
      "properties": {
        "new_checkout": {"type": "boolean"}
      }
    },
    "limits": {
      "type": "object",
      "required": ["retry_attempts"],
      "properties": {
        "retry_attempts": {"type": "integer", "minimum": 0, "maximum": 5}
      }
    }
  }
});

Then map the validated JSON into a typed model instead of letting dynamic leak through your app:

class AppConfig {
  final String version;
  final bool newCheckoutEnabled;
  final int retryAttempts;

  const AppConfig({
    required this.version,
    required this.newCheckoutEnabled,
    required this.retryAttempts,
  });

  factory AppConfig.fromValidatedJson(Map<String, dynamic> json) {
    final features = json['features'] as Map<String, dynamic>;
    final limits = json['limits'] as Map<String, dynamic>;

    return AppConfig(
      version: json['version'] as String,
      newCheckoutEnabled: features['new_checkout'] as bool,
      retryAttempts: limits['retry_attempts'] as int,
    );
  }
}

Fetching without trusting blindly

Here is a small repository that fetches config, validates it, caches the last known good value, and falls back safely.

import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:json_schema/json_schema.dart';
import 'package:shared_preferences/shared_preferences.dart';

class ConfigValidationException implements Exception {
  final String message;

  ConfigValidationException(this.message);

  @override
  String toString() => 'ConfigValidationException: $message';
}

class RemoteConfigRepository {
  final Uri configUrl;
  final http.Client _client;
  final AppConfig _fallback;

  static const _cacheKey = 'remote_config_v1';

  RemoteConfigRepository({
    required this.configUrl,
    http.Client? client,
    required AppConfig fallback,
  })  : _client = client ?? http.Client(),
        _fallback = fallback;

  Future<AppConfig> load() async {
    try {
      final response = await _client.get(configUrl).timeout(
            const Duration(seconds: 5),
          );

      if (response.statusCode != 200) {
        throw Exception('HTTP ${response.statusCode}');
      }

      final decoded = jsonDecode(response.body) as Map<String, dynamic>;
      final result = appConfigSchema.validate(decoded);

      if (!result.isValid) {
        throw ConfigValidationException(result.errors.toString());
      }

      final config = AppConfig.fromValidatedJson(decoded);

      try {
        await _cache(config);
      } catch (_) {}

      return config;
    } catch (_) {
      return await _lastKnownGood() ?? _fallback;
    }
  }

  Future<void> _cache(AppConfig config) async {
    final prefs = await SharedPreferences.getInstance();

    await prefs.setString(
      _cacheKey,
      jsonEncode({
        'version': config.version,
        'features': {
          'new_checkout': config.newCheckoutEnabled,
        },
        'limits': {
          'retry_attempts': config.retryAttempts,
        },
      }),
    );
  }

  Future<AppConfig?> _lastKnownGood() async {
    final prefs = await SharedPreferences.getInstance();
    final raw = prefs.getString(_cacheKey);

    if (raw == null) return null;

    try {
      final json = jsonDecode(raw) as Map<String, dynamic>;
      if (appConfigSchema.validate(json).isValid) {
        return AppConfig.fromValidatedJson(json);
      }
    } catch (_) {
      // Ignore corrupted cache and fall back.
    }

    return null;
  }
}

Common mistakes to avoid

1. Skipping schema validation

If a bad config can take down your app, validation is not optional. Schema validation gives you a clear failure point before the app state changes.

2. Using Map<String, dynamic> throughout the app

Remote JSON should be parsed once, validated once, and converted into a typed model. After that, your UI should depend on AppConfig, not raw maps.

3. Forgetting versioning

Include a version field. It helps with debugging, cache invalidation, and gradual rollout. You do not need a full backend admin panel to benefit from this.

4. Applying config non-atomically

Do not update some fields while leaving others unchanged. Replace the entire validated config object in one step. This prevents mixed states like “new checkout enabled but retry limits from an older config.”

5. Treating network failures as fatal

Remote config should improve behavior when available, not break startup when unavailable. A fallback config keeps the app usable.

When this approach makes sense

A Firebase-free remote config system is a good fit when:

  • your app is small enough that a simple JSON endpoint is sufficient;
  • you need self-hosted configuration;
  • you want to avoid third-party SDKs;
  • you need strict control over what config changes are allowed;
  • you care about preventing broken payloads at the app boundary.

The core idea is simple: remote configuration should be treated like code deployment. Define a schema, validate every payload, swap configs atomically, and keep a safe fallback. With that discipline, Flutter apps can get dynamic configuration updates without depending on Firebase.

This blog is produced with the assistance of AI by a human editor. Learn more

Related Posts

Cover image for Choosing the Right Storage for Flutter: Beyond SharedPreferences for Persistent Data

Choosing the Right Storage for Flutter: Beyond SharedPreferences for Persistent Data

Developers frequently struggle with persistent storage in Flutter, especially when dealing with OS-level backups and app reinstalls. This post will clarify the nuances of different storage solutions like `SharedPreferences`, `path_provider`, and `flutter_secure_storage`, focusing on how to correctly manage data lifetimes (per-install vs. per-user) and avoid issues like device IDs migrating to new phones or data being unexpectedly backed up.

Cover image for Optimizing Flutter UI Performance: Solving `ImageFiltered` Lag and Smooth Blurring

Optimizing Flutter UI Performance: Solving `ImageFiltered` Lag and Smooth Blurring

Flutter's `ImageFiltered` can cause significant lag when blurring large or frequently changing content like text. This post will explain the performance bottlenecks, provide solutions like caching blurred outputs with `RepaintBoundary` or `SnapshotWidget`, and offer practical tips to ensure smooth UI effects without sacrificing frame rates.