remote_config_feature_manager 3.0.4 copy "remote_config_feature_manager: ^3.0.4" to clipboard
remote_config_feature_manager: ^3.0.4 copied to clipboard

Firebase Remote Config feature manager for developer preferences, experiments, A/B tests etc.

Remote Config Feature Manager for Flutter #

[License: MIT]

Feature manager allows you to hide some unfinished/secret feature from your users, or experiments, that can be managed from remote data source or local settings.

If you need only local feature toggles or preferences use Feature Manager

Example 01 Example 02

Getting Started #

Installation #

Add

dependencies:
  remote_config_feature_manager: ^latest_version

dev_dependencies:
  build_runner:
  feature_manager_generator: ^latest_version
copied to clipboard

to your pubspec.yaml, and run

flutter packages get
copied to clipboard

in your project's root directory.

Setup Firebase Remote Config in your project. #

To get started with Firebase Remote Config for Flutter, please see the documentation available at https://firebase.flutter.dev

Basic Usage #

Creating Features with Code Generation

Starting from version 3.0.0, feature_manager supports code generation to simplify feature creation and management.

Steps to Use Code Generation:

  1. Add Annotations to Your Features

Create a Dart file (e.g., app_features.dart) and define your features using the provided annotations:

import 'package:feature_manager/annotations.dart';
import 'package:feature_manager/feature.dart';
import 'package:feature_manager/feature_manager.dart';

part 'features.g.dart';

@FeatureManagerInit()
class AppFeatures {
  AppFeatures({
    required this.textFeature,
    required this.booleanFeature,
    required this.doubleFeature,
    required this.integerFeature,
    required this.jsonFeature,
  });

  factory AppFeatures.instance() => _$AppFeatures();

  @FeatureOptions(
    key: 'dev-prefs-text-pref',
    remoteSourceKey: 'REMOTE-KEY-dev-prefs-text-pref',
    title: 'Text pref',
    description: 'This is text preference',
    defaultValue: 'Some default text',
  )
  final TextFeature textFeature;

  @FeatureOptions(
    key: 'dev-prefs-bool-pref',
    title: 'Toggle pref',
    description: 'This is toggle preference',
    defaultValue: false,
  )
  final BooleanFeature booleanFeature;

  @FeatureOptions(
    key: 'dev-prefs-double-pref',
    title: 'Number double pref',
    description: 'This is number double preference',
    defaultValue: 2.2,
  )
  final DoubleFeature doubleFeature;

  @FeatureOptions(
    key: 'dev-prefs-integer-pref',
    title: 'Number integer pref',
    description: 'This is number integer preference',
    defaultValue: 1,
  )
  final IntegerFeature integerFeature;

  @FeatureOptions(
    key: 'dev-prefs-json-pref',
    title: 'Json pref',
    description: 'This is json preference',
    defaultValue: {"value": "Json default value"},
  )
  final JsonFeature jsonFeature;
}
copied to clipboard
  • Annotations: Use the @FeatureManagerInit() annotation on the AppFeatures class to indicate that code should be generated.
  • Feature Fields: Annotate each feature field with @FeatureOptions() and provide the necessary parameters.
  • Factory Constructor: The factory AppFeatures.instance() returns an instance of the generated class _$AppFeatures().
  • Part Directive: The part 'features.g.dart'; directive tells Dart where to find the generated code.
  1. Run the Code Generator

Execute the following command to generate the feature classes:

flutter packages pub run build_runner build
copied to clipboard
  1. Use the Generated Features

Import the generated file and use the features in your code:

import 'features.dart';
// The generated part file is automatically included due to the 'part' directive.

void main() {
  final appFeatures = AppFeatures.instance();

  // Access individual features
  final textValue = appFeatures.textFeature.value;
  final isEnabled = appFeatures.booleanFeature.isEnabled;

  // Access all features using the extension
  for (final feature in appFeatures.values) {
    print('Feature key: ${feature.key}');
  }
}
copied to clipboard
  • Accessing Features: You can access each feature via the instance of AppFeatures.
  • Using the Extension: An extension AppFeaturesExt is generated to provide a values getter, which returns a list of all features.

Activate feature manager #

To fetch and active feature values use activate function. You should call RemoteConfigFeatureManager.getInstance() function to initialize RemoteConfigFeatureManager instance with its dependencies. After that you can use RemoteConfigFeatureManager.instance all over the app.

...
final featureManager =
      await RemoteConfigFeatureManager.getInstance();

await featureManager.activate(
            Features.values,
            minimumFetchInterval: const Duration(
                  minutes: 5,
            ),
      );
...
copied to clipboard

If you want to initialize FirebaseRemoteConfig elsewhere, you can just use refresh function to map remote values to your features.

...
featureManager.refresh(Features.values);
...
copied to clipboard

Using Features

To check whether a feature is enabled using RemoteConfigFeatureManager, you can create an instance via dependency injection (e.g., Provider, GetIt) or directly:

import 'package:feature_manager/feature_manager.dart';

final featureManager = RemoteConfigFeatureManager.instance;

final appFeatures = AppFeatures.instance();

// Check if a feature is enabled
final isEnabled = featureManager.isEnabled(appFeatures.booleanFeature);
copied to clipboard

Alternatively, since each feature provides an isEnabled property, you can directly access it:

final isEnabled = featureManager.booleanFeature.isEnabled;
// OR
final isEnabled = appFeatures.booleanFeature.isEnabled;
copied to clipboard

Modify remote feature values in Firebase Console

Example 01

Modify feature values in DEBUG (develop) mode

To do it, you can simply open DeveloperPreferences screen in any part of your app. You should pass list of your features as parameter for this screen.

P.S. You should hide this button for production builds.

Navigator.of(context).push(
  MaterialPageRoute(
    builder: (BuildContext context) =>
      DeveloperPreferencesScreen(Features.values),
    ),
);
copied to clipboard

Feature parameters #

Parameter Default Description
key String required This key will be used to store value in local storage.
type FeatureType FeatureType.feature It can be used to separate local features and experiments driven by some remote provider.
remoteSourceKey String Key from remote source.
description String Description that will be used inside Developer Preferences Screen.
value Object? Null Stored value of the Feature. Will be fetched from local storage.
defaultValue Object? Null Default value of the Feature. Will be returned by FeatureManager if stored value is Null
enum FeatureType { feature, experiment }
copied to clipboard
enum FeatureValueType { text, toggle, doubleNumber, integerNumber, json }
copied to clipboard

Contributions #

Feel free to contact me (agetman@bedcode.dev) or create Pull Requests/Issues for this repository :)

2
likes
150
points
247
downloads

Publisher

verified publisherbedcode.dev

Weekly Downloads

2024.08.11 - 2025.02.23

Firebase Remote Config feature manager for developer preferences, experiments, A/B tests etc.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

feature_manager, firebase_remote_config, flutter, shared_preferences

More

Packages that depend on remote_config_feature_manager