Flutter Integration Guide

Flutter Feature Flags

Feature flags for Flutter — remote toggles for iOS, Android, and web apps

Quick Start

1. Get your API key

Sign up at flagbit.anethoth.com to get your SDK key. The free tier includes 1,000 evaluations/day.

2. Install (optional)

flutter pub add http

3. Evaluate flags

import 'dart:convert';
import 'package:http/http.dart' as http;

class FlagBit {
  static const String _url = 'https://flagbit.anethoth.com/api/v1/evaluate';
  static String sdkKey = const String.fromEnvironment('FLAGBIT_SDK_KEY');
  static final Map<String, bool> _cache = {};

  static Future<bool> isEnabled(String flagKey, {Map<String, String>? context}) async {
    final cacheKey = '\$flagKey:\${context.hashCode}';
    if (_cache.containsKey(cacheKey)) return _cache[cacheKey]!;

    try {
      final resp = await http.post(
        Uri.parse(_url),
        headers: {'Content-Type': 'application/json', 'X-SDK-Key': sdkKey},
        body: jsonEncode({'flag_key': flagKey, 'context': context ?? {}}),
      );
      final value = jsonDecode(resp.body)['value'] as bool;
      _cache[cacheKey] = value;
      return value;
    } catch (_) {
      return false;
    }
  }
}

// Widget usage
class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FutureBuilder<bool>(
      future: FlagBit.isEnabled('new-home-layout', context: {'user_id': userId}),
      builder: (ctx, snapshot) {
        if (snapshot.data == true) {
          return NewHomeLayout();
        }
        return ClassicHomeLayout();
      },
    );
  }
}

// Provider pattern for app-wide flags
class FeatureFlagProvider extends ChangeNotifier {
  final Map<String, bool> _flags = {};

  Future<void> loadFlags(List<String> keys) async {
    for (final key in keys) {
      _flags[key] = await FlagBit.isEnabled(key);
    }
    notifyListeners();
  }

  bool isEnabled(String key) => _flags[key] ?? false;
}

Use Cases for Flutter

UI Experiments

A/B test different layouts, color schemes, or navigation patterns on mobile devices.

Platform-Specific Features

Enable features only on iOS or Android using platform context in targeting rules.

Gradual Rollouts

Roll out new features to 5% of mobile users, then increase based on crash rates and feedback.

Kill Switch

Instantly disable a buggy feature on all mobile devices without pushing an app update.

How FlagBit Works

1

Create a Flag

Define flags in your FlagBit dashboard with targeting rules and rollout percentages.

2

Evaluate in Code

Call the evaluate endpoint from your Flutter app with user context for targeted rollouts.

3

Toggle Instantly

Enable, disable, or adjust rollouts in real-time. No redeployment needed.

FAQ

Cache flag values locally (SharedPreferences) for offline fallback. Refresh when connectivity returns.

Use FutureBuilder or load all flags at app startup via the Provider pattern shown above.

Yes — pass {'platform': 'ios'} or {'platform': 'android'} in the context for platform-specific targeting.

FlagBit works identically in Flutter web — it's just an HTTP call.

Start using feature flags in Flutter

Free tier includes 1 project, 10 flags, and 1,000 evaluations/day. No credit card required.

Get Your Free API Key