> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/feature-management-experimentation/new-to-fme/sdks-and-customer-deployed-components/client-side-sdks/client-side-standard-sdks/dart-sdk.md).

# Dart SDK

Add feature flags and experimentation to your Dart and Flutter applications with the Harness FME Dart Client SDK, running on the Dart VM and Flutter across Android, iOS, Web, and Desktop.

Add feature flags and experimentation to your Dart and Flutter applications with the Harness FME Dart Client SDK.

This guide provides detailed information about our Dart Client SDK, `splitio_client_side`. The SDK runs on the Dart VM and Flutter across every target platform (Android, iOS, Web, and Desktop), and is pure Dart with no `dart:html`, `dart:io`, or `dart:ffi` dependencies, so it works anywhere Dart or Flutter runs.

All of our SDKs are open source. Go to our [Dart Client SDK GitHub repository](https://github.com/splitio/dart-client) to see the source code, or view the package on [pub.dev](https://pub.dev/packages/splitio_client_side).

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

This SDK requires Dart SDK v3.0.0 or later.

### Initialization <a href="#initialization" id="initialization"></a>

Set up Harness FME in your code base with the following steps:

#### 1. Add the package to your pubspec.yaml file <a href="#id-1-add-the-package-to-your-pubspecyaml-file" id="id-1-add-the-package-to-your-pubspecyaml-file"></a>

```yaml
dependencies:
  splitio_client_side: ^1.1.0
```

#### 2. Instantiate the SDK factory <a href="#id-2-instantiate-the-sdk-factory" id="id-2-instantiate-the-sdk-factory"></a>

```dart
import 'package:splitio_client_side/splitio_client_side.dart';

final factory = SplitFactory.create(
  'YOUR_SDK_KEY',
  const SplitClientConfig(),
  'CUSTOMER_ID',
);
final client = factory.client('CUSTOMER_ID');
```

Configure the SDK with the SDK key for the FME environment that you would like to access. Select a client-side SDK API key. This is a special type of API token with limited privileges for use in browsers or mobile clients. See [API keys](/feature-management-experimentation/management-and-administration/api-keys.md) to learn more.

### Using the SDK <a href="#using-the-sdk" id="using-the-sdk"></a>

#### Basic use <a href="#basic-use" id="basic-use"></a>

When the SDK is instantiated, it starts background tasks to update an in-memory cache with small amounts of data fetched from Harness servers. Because this SDK is meant to be used client-side, don't block your app on SDK readiness. Instead, subscribe to the `whenReady()` future, as shown below.

After the SDK is ready, use the `getTreatment` method to return the proper treatment based on the `FEATURE_FLAG_NAME` and the key you passed when instantiating the client. Then use an if-else-if block as shown below and insert the code for the different treatments that you defined in Harness FME. Remember the final else branch in your code to handle the client returning [the control treatment](/feature-management-experimentation/use-fme/feature-management/setup/control-treatment.md).

```dart
client.whenReady().then((_) {
  final treatment = client.getTreatment('FEATURE_FLAG_NAME');

  if (treatment == 'on') {
    // on-treatment code
  } else if (treatment == 'off') {
    // off-treatment code
  } else {
    // control-treatment code
  }
});
```

#### Subscribe to updates <a href="#subscribe-to-updates" id="subscribe-to-updates"></a>

Because feature flag definitions can change at any time, listen to the client's `whenUpdated()` stream to know when to re-evaluate flags, rather than relying on a value you evaluated earlier in the session.

```dart
client.whenUpdated().listen((changedFlags) {
  // re-evaluate flags in `changedFlags`
});
```

### Reference links <a href="#reference-links" id="reference-links"></a>

* Repo: <https://github.com/splitio/dart-client>
* Issues: <https://github.com/splitio/dart-client/issues>
* Pub.dev: <https://pub.dev/packages/splitio_client_side>

Questions or feedback? Reach out to your Harness account team, or open an issue in the GitHub repository above.
