/flutter-remote-config

Primary LanguageDartBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

firebase_remote_config plugin

A Flutter plugin to use the Firebase Remote Config API.

pub package

For Flutter plugins for other Firebase products, see README.md.

Usage

Import the firebase_remote_config plugin

To use the firebase_remote_config plugin, follow the plugin installation instructions.

Android integration

Enable the Google services by configuring the Gradle scripts as such.

  1. Add the classpath to the [project]/android/build.gradle file.
dependencies {
  // Example existing classpath
  classpath 'com.android.tools.build:gradle:3.5.4'
  // Add the google services classpath
  classpath 'com.google.gms:google-services:4.3.4'
}
  1. Add the apply plugin to the [project]/android/app/build.gradle file.
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

Note: If this section is not completed you will get an error like this:

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

Note: When you are debugging on android, use a device or AVD with Google Play services. Otherwise you will not be able to use Firebase Remote Config.

Use the plugin

Add the following imports to your Dart code:

import 'package:firebase_remote_config/firebase_remote_config.dart';

Initialize RemoteConfig:

final RemoteConfig remoteConfig = await RemoteConfig.instance;

You can now use the Firebase remoteConfig to fetch remote configurations in your Dart code, e.g.

final defaults = <String, dynamic>{'welcome': 'default welcome'};
await remoteConfig.setDefaults(defaults);

await remoteConfig.fetch(expiration: const Duration(hours: 5));
await remoteConfig.activateFetched();
print('welcome message: ' + remoteConfig.getString('welcome'));

Example

See the example application source for a complete sample app using the Firebase Remote Config.

Issues and feedback

Please file FlutterFire specific issues, bugs, or feature requests in our issue tracker.

Plugin issues that are not specific to Flutterfire can be filed in the Flutter issue tracker.

To contribute a change to this plugin, please review our contribution guide and open a pull request.