mirror of
https://github.com/BillyOutlast/posthog.com.git
synced 2026-02-09 22:01:20 +01:00
36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
### Boolean feature flags
|
||
|
||
```dart
|
||
if (await Posthog().isFeatureEnabled('flag-key')) {
|
||
// Do something differently for this user
|
||
|
||
// Optional: fetch the payload
|
||
final matchedFlagPayload = await Posthog().getFeatureFlagPayload('flag-key');
|
||
}
|
||
```
|
||
|
||
### Multivariate feature flags
|
||
|
||
```dart
|
||
if (await Posthog().getFeatureFlag('flag-key') == 'variant-key') { // replace 'variant-key' with the key of your variant
|
||
// Do something differently for this user
|
||
|
||
// Optional: fetch the payload
|
||
final matchedFlagPayload = await Posthog().getFeatureFlagPayload('flag-key');
|
||
}
|
||
```
|
||
|
||
### Ensuring flags are loaded before usage
|
||
|
||
Every time a user opens the app, we send a request in the background to fetch the feature flags that apply to that user. We store those flags in the storage.
|
||
|
||
This means that for most screens, the feature flags are available immediately – **except for the first time a user visits**.
|
||
|
||
### Reloading feature flags
|
||
|
||
Feature flag values are cached. If something has changed with your user and you'd like to refetch their flag values, call:
|
||
|
||
```dart
|
||
await Posthog().reloadFeatureFlags();
|
||
```
|