Skip to content

Conversation

@motrieux-thomas
Copy link

Fix: Encrypted features not loading from network fetch

Problem

When encryptionKey is configured, feature flags fail to load from the GrowthBook API.
The SDK initializes successfully but returns 0 features instead of the expected encrypted features.

Root Cause

The _handleSuccess method in FeatureViewModel was directly accessing data.features!
when processing API responses. However, when encryption is enabled, the GrowthBook API
returns:

  • data.features = null or empty
  • data.encryptedFeatures = encrypted string

This caused the encrypted features to be ignored completely.

Solution

Changed _handleSuccess to use prepareFeaturesData(data) instead of directly accessing
data.features. This method correctly routes the response based on whether encryption is
enabled:

  • Non-encrypted: Uses data.features directly
  • Encrypted: Calls handleEncryptedFeatures to decrypt data.encryptedFeatures

Changes

  • lib/src/Features/features_view_model.dart: Modified _handleSuccess implementation
  • test/common_test/sdk_builder_test.dart: Updated test encrypted string format

Testing

  • ✅ All 37 existing tests pass
  • ✅ Encryption now works correctly (tested with real GrowthBook API)
  • ✅ Non-encrypted mode still works (backward compatible)
  • ✅ Verified with both cached and fresh network fetches

Impact

  • Fixes encrypted feature flag loading introduced in v4.0.0
  • No breaking changes
  • Backward compatible with non-encrypted configurations

When encryption is enabled, the API returns data.encryptedFeatures
instead of data.features. The _handleSuccess method was directly
accessing data.features!, which is null when encryption is enabled.

Changed _handleSuccess to use prepareFeaturesData which correctly
routes encrypted responses to handleEncryptedFeatures for decryption.

Fixes feature flag loading when encryptionKey is configured.
@vazarkevych
Copy link
Collaborator

Hi @motrieux-thomas, thanks for contribution! We have check the issue you reported and successfully reproduced the bug where encrypted features were not loading. We have also reviewed your PR, and your fix correctly resolves this problem.

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

Successfully merging this pull request may close these issues.

2 participants