feature_flags
此包仅允许您动态激活应用程序的功能。
用法
设置
将您的应用的 widget 包装在 Features widget 中。
Features(
child: MaterialApp(
/// ...
),
);
测试功能是否已启用
要测试功能是否已启用,请使用 Features.isFeatureEnabled 函数以及唯一的标识符。
if (Features.isFeatureEnabled(context, 'DECREMENT')) {
/// The 'DECREMENT' feature is enabled
}
启用或禁用功能
从 Features widget 中
通过更新 Features widget 中的 flags。
Features(
flags: [ 'DECREMENT' ],
child: MaterialApp(
/// ...
),
);
在代码中本地启用
您可以通过调用 Features.setFeature 函数来激活一个功能。该功能标志保存在共享偏好设置中,并在会话之间持久化。
Features.setFeature(
context,
'DECREMENT',
true,
);
使用调试视图
调试视图允许您的用户激活或禁用任何动态功能。
这在开发过程中可能很有用,但应谨慎使用。
DebugFeatures.show(
context,
availableFeatures: [
Feature('DECREMENT', name: 'Decrement'),
Feature('RESET', name: 'Reset'),
],
);