breezy-activity-86410
07/09/2024, 7:09 PMrhythmic-agent-34208
07/09/2024, 7:54 PMbreezy-activity-86410
07/09/2024, 8:00 PMclass GrowthBookProvider with ProviderLoggy {
const GrowthBookProvider();
static const _apiKey = 'sdk-api-key';
static const _hostURL = '<https://cdn.growthbook.io/>';
static late final GrowthBookSDK _growthBook;
Future<Experiments> init(String userId) async {
_growthBook = await GBSDKBuilderApp(
apiKey: _apiKey,
hostURL: _hostURL,
attributes: {
'id': userId,
},
growthBookTrackingCallBack: (gbExperiment, gbExperimentResult) {},
).initialize();
final featureFlags = <FeatureFlag, FeatureFlagResult<dynamic>>{
for (final featureFlag in FeatureFlag.values)
featureFlag: () {
final result = _growthBook.feature(featureFlag.id);
logInfo('Feature flag: ${featureFlag.id}, '
'value: ${result.value}, source: ${result.source}');
final experimentResult = (result.experiment != null &&
result.experimentResult != null)
? ExperimentResult(
experimentId: result.experiment!.key!,
variantId: result.experimentResult!.variationID!.toString(),
)
: null;
return switch (featureFlag.type) {
FeatureFlagType.bool => FeatureFlagResult<bool>(
feature: featureFlag,
value:
result.value as bool? ?? featureFlag.defaultValue as bool,
experimentResult: experimentResult,
),
};
}(),
};
return Experiments(
allFeatureFlags: featureFlags,
);
}
}
enum FeatureFlag {
wappShort('wapp_short', FeatureFlagType.bool, false),
wappPick('wapp_pick', FeatureFlagType.bool, false),
moreRecipes('wapp_paywall', FeatureFlagType.bool, false),
;
const FeatureFlag(this.id, this.type, this.defaultValue);
final String id;
final FeatureFlagType type;
final dynamic defaultValue;
}
breezy-activity-86410
07/09/2024, 8:02 PMbrief-honey-45610
07/10/2024, 4:14 PMmost-spoon-61816
07/10/2024, 4:19 PM