Help Instance Help

m8ty_feature_flags

What features exist and how can the features be activated/deactivated based on some information (user, application, version, timing etc.)? This library should be used for the integration inside the app relaying on the configuration of those flags. Based on the flag a feature will be displayed or not. This library supports the app in reading the flags and rendering the widgets based on those flags.

Setup the package

Define all the features using type safety

Using string as feature names is not an option. A possible approach is to use enums

enum MyFeatures { paymentsInternation("payments_international"), assetsAccountsGet("assets_accounts_get"); const MyFeatures(this.value); final String value; }

Install package

m8ty_device_info: git: git@gitlab.m8ty.eu:app-framework/infra/m8ty_feature_flags.git

Initialize the package

void main() async { WidgetsFlutterBinding.ensureInitialized(); await M8tyFeatures.initialize( apiKey: "85e2f8cf-88a2-4e75-aedb-6b5742749088", baseUrl: "https://api-dev-mock.m8ty.eu/api/v1", features: {MyFeatures.paymentsInternation.value: true, MyFeatures.assetsAccountsGet.value: false}, refreshInterval: Duration(seconds: 5)); runApp(const MyApp()); }

Parameter

Description

apiKey

Key configured on the server so that you can access the API

features

A list of all available features and if those features are enabled or disabled by default

baseUrl

Url to the server API responsible for tracking

refreshInterval

How often should the configuration be retrieved from the server. Initial retrieve happens during the app startup

callback

Callback is being called whenever a feature is being rendered. This is very helpful for analytics

Check if a feature is enabled

There are different options to check if a certain feature is active. Based on the feature flag, the application may change its behavior.

Check if one feature is enabled

This is the simplest use case. We have one feature and we are checking if its active or not

M8tyFeatures.instance.isFeatureEnabledOne(MyFeatures.paymentsInternation.value);

Check if one feature is disabled

M8tyFeatures.instance.isFeatureDisabledOne(MyFeatures.assetsAccountsGet.value);

Check if all features in the list are enabled

M8tyFeatures.instance.isFeatureEnabled( [MyFeatures.paymentsInternation.value, MyFeatures.assetsAccountsGet.value], )

Check if any of the features in the list is enabled

Therefore the property requirement is used with the value FeatureRequirement.any. The default is FeatureRequirement.all and is used in all the examples above.

M8tyFeatures.instance.isFeatureEnabled( [MyFeatures.paymentsInternation.value, MyFeatures.assetsAccountsGet.value], requirement: FeatureRequirement.any), true)

Negation

Of course the negation of the condition can be set as well. This means the evaluated output will be negated (NOT)

M8tyFeatures.instance.isFeatureEnabled([MyFeatures.paymentsInternation.value], negate: true)

Conditional rendering of widgets

But how now based on the feature flag to display a widget or not. Therefore the M8tyFeature has been introduced

M8tyFeature( featureKeys: [MyFeatures.paymentsInternation.value], child: MyWidget(title: 'T', message: 'M'), );

If all the features being defined in the featureKeys are enabled, then the widget will be rendered. Of course all the above listed options are available.

Parameter

Description

featureKeys

List of features which should be checked

child

Child control which should be rendered if the feature is enabled

requirement

Are all features required to render the child widget

negate

Negate the condition of features list

type

Supporting widget or is it the real feature. The configuration is relevant for analytics

name

Optional name for the feature which is about to be reported to callback function defined during initialize. Also relevant for analytics

Analytics integration

For tracking integration there is an extra callback which is only being called in combination with the M8tyFeature widget. Please see therefore the callback named parameter in the initialize method. Here the data being passed in during the callback

class CallBackData { List<String> featureKeys; String? name; M8tyFeatureWidgetType widgetType; M8tyFeatureCallbackType type; CallBackData({ this.name, required this.featureKeys, this.type = M8tyFeatureCallbackType.display, this.widgetType = M8tyFeatureWidgetType.feature, }); }

Use without the server

If you want use the features without getting the flags from the server, all you need to do is not to set the api key. This way no requests will be sent toward the server.

Last modified: 07 January 2025