flipt 0.0.3 copy "flipt: ^0.0.3" to clipboard
flipt: ^0.0.3 copied to clipboard

A lightweight HTTP client for consuming Flipt feature flag snapshots using `description` as values.

example/lib/main.dart

// ignore_for_file: avoid_print

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flipt/flipt.dart';
import 'package:shared_preferences/shared_preferences.dart';

/// A [FliptStorage] implementation backed by [SharedPreferences].
///
/// Stores and retrieves cached feature flag snapshots using a provided [key].
class FliptSharedPreferencesStorage implements FliptStorage {
  /// Creates a new storage instance with the given [key].
  FliptSharedPreferencesStorage(this.key);

  /// Key used for storing cached flag data in [SharedPreferences].
  final String key;

  /// Lazily initialized instance of [SharedPreferences].
  late SharedPreferences _prefs;

  @override
  Future<void> init() async {
    _prefs = await SharedPreferences.getInstance();
  }

  @override
  Future<String?> get() async {
    return _prefs.getString(key);
  }

  @override
  Future<void> put(String value) async {
    await _prefs.setString(key, value);
  }
}

Future<void> main() async {
  final flipt = Flipt(
    host: 'feature-flags.example.com',
    token: 'your-api-token',
    namespace: 'production',
    environment: 'mobile-app',
    context: const {'app_version': '2.5.0', 'platform': 'ios'},
    defaultValues: {
      'new_checkout_flow': false,
      'max_recommendations': 6,
      'api_base_url': 'https://api.example.com',
      'checkout_thresholds': const <String, Object>{
        'caution': 0.6,
        'critical': 0.9,
      },
      'supported_locales': const <Object>['en', 'vi'],
    },
    storage: FliptSharedPreferencesStorage('Flipt'),
    fetchInterval: const Duration(minutes: 15),
    timeout: const Duration(seconds: 5),
    shouldFetchFromRemote: () async {
      final connected = await Connectivity().checkConnectivity();
      return !connected.contains(ConnectivityResult.none);
    },
    isDebug: true,
  );

  try {
    await flipt.ensureInitialized;

    final isCheckoutEnabled = flipt.getBool(
      'new_checkout_flow',
      defaultValue: false,
    );
    final recommendationLimit = flipt.getInt(
      'max_recommendations',
      defaultValue: 3,
    );
    final apiUrl = flipt.getString('api_base_url');
    final thresholds = flipt.getMap<double>('checkout_thresholds');
    final locales = flipt.getList<String>('supported_locales');

    print('Checkout enabled: $isCheckoutEnabled');
    print('Recommendation limit: $recommendationLimit');
    print('API base URL: $apiUrl');
    print('Checkout thresholds: $thresholds');
    print('Supported locales: $locales');
  } finally {
    flipt.dispose();
  }
}
0
likes
160
points
35
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A lightweight HTTP client for consuming Flipt feature flag snapshots using `description` as values.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on flipt