Creating a Feature Provider

In this codelab, we'll be creating a Feature Provider that fetches JSON asset. But the feature provider that can be created is not limited to JSON file or asset, since Clean Framework follows Open Feature Standard, the feature flagging is vendor-independent. Thus, these provider can be created for any vendor that follows Open Feature Standard.

AssetFeatureProvider

  1. Create a file named asset_feature_provider.dart.
  2. Add the following content to the file.
class AssetFeatureProvider extends JsonFeatureProvider {
  Future<void> load(String key) async {
    final rawFlags = await rootBundle.loadString(key);

    feed(jsonDecode(rawFlags));
  }
}

Note: JsonFeatureProvider is a helper class provider by Clean Framework to help with parsing JSON flag schema. For vendors that doesn't use JSON, FeatureProvider class can be used.

feed()

The feed method used above feeds the JSON obtained from asset to an underlying evaluation engine, which is responsible for evaluating flag object for each flag key.