• HOME
  • INTEGRATIONS
  • SDKS
  • GUIDES
  • API DOCS
No results for ""
EXPAND ALL

EDIT ON GITHUB

Flutter SDK reference

Read time: 1 minute
Last edited: Jul 28, 2021
This SDK is in beta

The Flutter SDK is currently in beta and undergoing active development. Elements of this SDK may change without notice. Do not use this SDK in production environments.

Overview

This reference guide documents the methods available in the Flutter SDK, and explains in detail how these methods work. If you want to dig even deeper, our SDKs are open source. To learn more, view the source on GitHub or the generated API documentation. Additionally you can clone and run a sample application that uses this SDK.

Supported platforms

The Flutter SDK supports Android API 16+ and iOS 10.0+.

Getting started

Building on top of our Getting Started guide, the following steps will get you started with using the LaunchDarkly SDK in your Flutter mobile application.

To get started, declare a dependency on the LaunchDarkly Flutter SDK:

1launchdarkly_flutter_client_sdk: ^0.1.0

Then, import the package in your application code:

1import 'package:launchdarkly_flutter_client_sdk/launchdarkly_flutter_client_sdk.dart';

After you install the SDK, initialize the single shared instance of LDClient. Specify your mobile key here. This authorizes your application to connect to LaunchDarkly and retrieve flag values for your application and environment.

The following example shows the simplest way to create the client:

1LDConfig config = LDConfigBuilder('YOUR_MOBILE_KEY').build();
2LDUser user = LDUserBuilder('user key')
3 .email('fake@example.com')
4 .build();
5
6await LDClient.start(config, user);
Use a mobile key

Always use a mobile key from your Environments page. Never embed a server-side SDK key into a mobile application.

Using LDClient, you can check which variation a particular user should receive for a given feature flag:

1bool showFeature = await LDClient.boolVariation(flagKey, false);
2if (showFeature) {
3 // application code to show the feature
4}
5else {
6 // the code to run if the feature is off
7}

Lastly, shut down the client when your application terminates. To learn more, read Shutting down.

Data collection

To learn more about data collection within this SDK and implications on submissions to the Apple App Store, read Apple App Store data collection policy.

Supported features

This SDK supports the following features: