标志功能

最初是 fire_flag 的一个分支,并持续开发和更新。

应用范围内的功能标志管理器。利用 Firebase Remote Config 的强大功能管理应用程序中各项功能的可用状态。

安装

将 Flag Feature 添加到您的 pubspec.yaml 文件中

dependencies:
  flag_feature: ^2.0.1

用法

添加 Firebase 配置文件

将所需的 GoogleServiceInfo.plist(用于 iOS)和 google_services.json(用于 Android)分别添加到您的项目中。有关添加 Firebase 配置文件的更多信息,请参阅 此处

Firebase Remote Config Android 集成

通过如下配置 Gradle 脚本来启用 Google 服务。

  1. 将 classpath 添加到 [project]/android/build.gradle 文件中。

dependencies {
  // Example existing classpath
  classpath 'com.android.tools.build:gradle:3.2.1'
  // Add the google services classpath
  classpath 'com.google.gms:google-services:4.3.0'
}
  1. 将 apply plugin 添加到 [project]/android/app/build.gradle 文件中。

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

注意: 如果此部分未完成,您将收到类似以下的错误

java.lang.IllegalStateException:
Default FirebaseApp is not initialized in this process [package name].
Make sure to call FirebaseApp.initializeApp(Context) first.

注意: 在 Android 上调试时,请使用具有 Google Play 服务的设备或 AVD。否则,您将无法使用 Firebase Remote Config 和 Fire Flag。

使用插件

将以下导入添加到您的 Dart 代码中

import 'package:flag_feature/flag_feature.dart';

初始化 FeatureFlag

static final features = Features(features: [
    Feature(
      name: 'brandOverview', // Feature name, must be the same with the name on (Firebase Remote Config console)[https://console.firebase.google.com/]. 
      isEnabled: false, // Feature status
    ),
  ]);

var featureFlag = FeatureFlag(
    features: features
    ),

您现在可以订阅功能标志订阅流以获取功能的最新状态。

Features _features = features;

featureFlag
    .featureFlagSubscription()
    .listen((updatedFeatures) {
      _features = updatedFeatures
});

示例

有关使用 Fire Flag 的完整示例应用程序,请参阅 示例应用程序 源代码。

问题和反馈

请在我们的 问题跟踪器 中提交具体的问题、错误或功能请求。

要为该插件贡献更改,请提交一个 拉取请求

GitHub

查看 Github