Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keys are not being picked up #3

Open
FilledStacks opened this issue Dec 16, 2020 · 1 comment
Open

Keys are not being picked up #3

FilledStacks opened this issue Dec 16, 2020 · 1 comment

Comments

@FilledStacks
Copy link

We've integrated flagsmith with our Flutter client recently. We've been stuck for two days now with the value returning null for isFeatureFlagEnabled and false for hasFeatureFlag. This works perfectly fine on the website implementation. Below is the Service we're using and the logic to fetch the values.

@singleton

/// A wrapper service for the Bullet train library
class FlagsmithService {
  final log = getLogger('FlagsmithService');
  final _sharedPreferences = locator<SharedPreferencesService>();

  final _bulletTrainClient = BulletTrainClient(
    apiKey: FlavorConfig.instance.values.bulletTrainEnvironmentApiKey,
    config: BulletTrainConfig(
      isDebug: true,
    ),
  );

  bool _isSSOEnabled = false;
  bool _isThirdPartyEnabled = false;
  bool _isGoogleAuthEnabled = false;
  bool _isFacebookAuthEnabled = false;
  bool _isAppleAuthEnabled = false;

  Future initialise() async {
    _isSSOEnabled = await _getFeatureEnabled('auth');
    _isThirdPartyEnabled = await _getFeatureEnabled('third-party');
    _isGoogleAuthEnabled = await _getFeatureEnabled('google-login');
    _isFacebookAuthEnabled = await _getFeatureEnabled('facebook-login');
    _isAppleAuthEnabled = await _getFeatureEnabled('apple-login');
  }

  bool get isSSOEnabled => true; //_isSSOEnabled;
  bool get isThirdPartyEnabled => _isThirdPartyEnabled;
  bool get isGoogleAuthEnabled => _isGoogleAuthEnabled;
  bool get isFacebookAuthEnabled => _isFacebookAuthEnabled;
  bool get isAppleAuthEnabled => _isAppleAuthEnabled;

  Future<bool> _getFeatureEnabled(String key) async {
    final user = FeatureUser(
      identifier: _sharedPreferences.idempotencyKey,
    );

    var featureEnabledValue =
        await _bulletTrainClient.isFeatureFlagEnabled(key, user: user);

    var hasFeature = await _bulletTrainClient.hasFeatureFlag(key, user: user);

    log.d('hasFeature:$hasFeature key:$key');

    return featureEnabledValue ?? false;
  }
}

We triple double quadruple checked the api key and it's correct. We have tried a different one. One other thing to note is that it's not printing out any logs or throwing any exceptions. I've set isDebug to true but there's no logs to be found in the Debug Console.

@printeastwoodcz
Copy link
Collaborator

@FilledStacks Hi, thanks for your example.
You should use seeds for default values of your flags. BT will use values from seed before you update from api.

extension FlagX on Flag {
  static int generateNum(int min, int max) => min + Random().nextInt(max - min);
  static Flag seed(String featureName, {bool enabled = true, String value}) {
    var id = generateNum(1, 100);

    return Flag.named(
        id: id,
        stateValue: value,
        feature: Feature.named(
            id: id,
            name: featureName,
            createdDate: DateTime.now().add(Duration(days: generateNum(0, 10))),
            type: FlagType.flag),
        enabled: enabled);
  }
}
// prepare default values before you update new values from api
final seeds = [
FlagX.seed('third-party', true),
];
final bulletTrain = BulletTrainClient(
        apiKey: apiKey,
        seeds: seeds,
        config: BulletTrainConfig(storeType: StoreType.persistant));
        
await bulletTrain.getFeatureFlags(); // will trigger update from flagsmith api
bool isThirdParty = bulletTrain.hasFeatureFlag('third-party'); 
final thirdPartyValue = bulletTrain.getFeatureFlagValue('third-party'); 

isDebug currently logs only API calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant