runTest static method

Future<void> runTest(
  1. String testName,
  2. Function baseline,
  3. Map<String, Function> codeblocks, [
  4. int? updateMetadataTimeout,
])

Runs the code block A/B test specified by testName.

You must specify the baseline (default) code block to execute if we are enrolled in the default variant. Each of the variants are specified in the codeblocks Map keyed using strings. The string keys must match the name of the variant set in the Apptimize dashboard.

Additional updateMetadataTimeout in milliseconds may be specified.

When this method is called, one of the code block variants or the default code block will be run sychronously in accordance with the A/B test variant this user/device is enrolled in.

Implementation

static Future<void> runTest(
    String testName, Function baseline, Map<String, Function> codeblocks,
    [int? updateMetadataTimeout]) async {
  final String? codeblock = await _channel.invokeMethod('runTest', {
    "testName": testName,
    "codeBlocks": codeblocks.keys.toList(),
    "updateMetadataTimeout": updateMetadataTimeout
  });

  Function? block;

  if (codeblock != null) {
    block = codeblocks[codeblock];
    if (block == null) {
      developer.log(
          "`runTest` received unknown codeblock `$codeblock` in result, executing default.",
          name: Apptimize._logTag);
    }
  }

  block = block ?? baseline;
  block();
}