Coder Social home page Coder Social logo

printeastwoodcz / bullet_train_flutter Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 0.0 225 KB

License: MIT License

Kotlin 0.24% Swift 0.76% Objective-C 0.07% Dart 94.93% Ruby 2.53% Shell 1.47%
flutter feature-flags features traits feature-flag feature-flagging feature-flaggers remote-config ci cd

bullet_train_flutter's Introduction

Bullet Train SDK for Flutter

Bullet Train allows you to manage feature flags and remote config across multiple projects, environments and organisations.

The SDK for Flutter applications for https://bullet-train.io/.

Getting Started

The client library is available from the https://pub.dev:

dependencies:
  bullet_train:

Usage

Retrieving feature flags for your project

For full documentation visit https://docs.bullet-train.io

Sign Up and create an account at https://bullet-train.io/

In your application, initialise the BulletTrain client with your API key:

var bulletClient = BulletTrainClient(apiKey: 'YOUR_ENV_API_KEY')

To check if a feature flag exists and is enabled:

bool featureEnabled = await bulletClient.hasFeatureFlag("my_test_feature");
if (featureEnabled) {
    // run the code to execute enabled feature
} else {
    // run the code if feature switched off
}

To get the configuration value for a feature flag:

var myRemoteConfig = await bulletClient.getFeatureFlagValue("my_test_feature");
if (myRemoteConfig != null) {
    // run the code to use remote config value
} else {
    // run the code without remote config
}

Identifying users

Identifying users allows you to target specific users from the Bullet Train dashboard.

To check if a feature exists for a given user Identity:

var user = FeatureUser(identifier: 'bullet_train_sample_user');
bool featureEnabled = await bulletClient.hasFeatureFlag('my_test_feature', user: user);
if (featureEnabled) {
    // run the code to execute enabled feature for given user
} else {
    // run the code when feature switched off
}

To get the configuration value for a feature flag for given a user Identity:

var myRemoteConfig = await bulletClient.getFeatureFlagValue('my_test_feature', user: user);
if (myRemoteConfig != null) {
    // run the code to use remote config value
} else {
    // run the code without remote config
}

To get the user traits for given user Identity:

var userTraits = await bulletClient.getTraits(user)
if (userTraits != null && userTraits) {
    // run the code to use user traits
} else {
    // run the code without user traits
}

To get user trait for given user Identity and specific Trait key:

var userTrait = await bulletClient.getTrait(user, 'cookies_key');
if (userTrait != null) {
    // run the code to use user trait
} else {
    // run the code without user trait
}

Or get user traits for given user Identity and specific Trait keys:

 var userTraits = await bulletClient.getTraits(user, keys: ['cookies_key', 'other_trait']);
if (userTraits != null) {
    // run the code to use user traits
} else {
    // run the code without user traits
}

To update a user trait for given user Identity:

 var userTrait = await bulletClient.getTrait(user, 'cookies_key');
if (userTrait != null) {
    // update value for user trait
    var updatedTrait = userTrait.copyWith(value: 'new value');
    Trait updated = await bulletClient.updateTrait(user, updatedTrait);
} else {
    // run the code without user trait
}

Override default configuration

By default, the client uses the default configuration. You can override this configuration as follows:

var bulletClient = BulletTrainClient(
      config: BulletTrainConfig(
          baseURI: 'http://yoururl.com/'
      ), apiKey: 'YOUR_ENV_API_KEY');

Override the default configuration with your own:

final appDir = await getApplicationDocumentsDirectory();
await appDir.create(recursive: true);
final databasePath = join(appDir.path, 'bullt_train.db');

var bulletClient = BulletTrainClient(
      config: BulletTrainConfig(
          baseURI: 'http://yoururl.com/',
          connectTimeout: 200,
          receiveTimeout: 500,
          sendTimeout: 500,
          usePersitantStorage: true,
          persistantDatabasePath: databasePath,
      ), apiKey: 'YOUR_ENV_API_KEY');

Getting Help

If you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search existing issues in order to prevent duplicates.

Get in touch

If you have any questions about our projects you can email [email protected].

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.