AB Testing - Core

A Dart package that helps to implement multiple a/b tests.


This package simplifies the creation and management of multiple a/b tests. It comes with a local adapter for local a/b tests and can be extended with further adapters. It supports test values of the types bool, int, String and Enum.

The package ab_testing_firebase provides an additional firebase adapter that simplifies remote a/b tests.

Getting started

You need to add ab_testing_core to the dependencies of the pubspec.yaml.

ab_testing_core: ^1.0.0


You can create your own configuration that extends the ExperimentConfig class with all the adapters and experiments you need. Directly during initialisation, you can select which adapter should be used for the respective experiment.

class LocalExperimentConfig extends ExperimentConfig {
  final Experiment<bool> booleanExperiment;
  final Experiment<int> numericExperiment;
  final Experiment<String> textExperiment;
  final Experiment<ExampleEnum> enumeratedExperiment;

  LocalExperimentConfig(ExperimentAdapter localExperiments)
      : booleanExperiment = localExperiments.boolean(id: 'boolExperiment'),
        numericExperiment = localExperiments.numeric(id: 'intExperiment'),
        textExperiment = localExperiments.text(id: 'textExperiment'),
        enumeratedExperiment = localExperiments.enumerated(
          id: 'enumExperiment',
          defaultVariant: ExampleEnum.control,
          weightedVariants: {ExampleEnum.control: 1, ExampleEnum.test: 1},

After initialisation, you can pass your ExperimentAdapters to your ExperimentConfig.

final _localExperiments = LocalExperimentAdapter(_storage.userSeed);
final _experimentConfig = LocalExperimentConfig(_localExperiments);

Afterwards, you can easily access the experiments in your app via your Config.

bool get boolean => _experimentConfig.booleanExperiment.value;
int get numeric => _experimentConfig.numericExperiment.value;
String get text => _experimentConfig.textExperiment.value;
ExampleEnum get enumerated => _experimentConfig.enumeratedExperiment.value;