What is Firebase Remote Config

The name chosen by Google this time is very comprehensive and exhaustive. Firebase remote config is a remotely saved configuration, in this case on Google Cloud. This configuration is accessible to insert and update in the Firebase console, under the menu item Firebase remote config which is located at the very bottom, in the last section, in my opinion a little hidden.

Prerequisites:

By doing this we could use all the Firebase services, there are many online tutorials and Firebase itself provides wizards with steps to guide you to the correct implementation of Firebase with your app. We can use Firebase Remote Config to store everything our app needs as configuration parameters. First of all, We must identify and configure what we think will change over time. In this way we will have configurations in the app that can be modified in real time remotely so as not to have to carry out a new app deployment. An example may be the case in which we are using an API to recover data, the base url may change over time.

Another more down to earth-example that I use in the send to kindle app is a parameter that contains the number of actions before showing an advertisement. In this way, if users complain about too many advertisements, I can change it in real time with just changing a parameter into the web interface at no cost.

The Firebase system works really well, there is a push-lazy system behind it that uses internet data to retrieve the configurations only if we have really changed something on the server side and therefore we have published a change to one or more parameters. The updating of the parameters takes place in real time so it changes immediately the behavior, state or data in app as real time.

Parameters can also be associated with conditions. For example, a parameter can only be used for users of a certain age in a certain country or language at a specific time. Cool! isn’t it?

Advantages

  • Instant and simple remote control.

  • Real-time app customization.

  • It decreases the need for a new deployment.

  • Parameters can be combined with conditions.

How do I use it in my apps?

Below I want to show you an example of implementation. In this way I centralized the initialisation and parameter creation part so that they are more accessible. I decided to use a singleton so that I can use it in all the views and all the classes I need it, implemented in the following way:

import 'package:firebase_remote_config/firebase_remote_config.dart';
class Configuration {
int _link_sent_before_ads;
int _max_send_limit_size = 24000000;
int get linkSentBeforeAds => _link_sent_before_ads;
int get maxSendLimitSize => _max_send_limit_size;
int get maxSendLimitSizeMb => (_max_send_limit_size/1000000).round();
static Configuration get instance => _instance;
static final Configuration _instance = Configuration._privateConstructor();
Configuration._privateConstructor()
{
  //initializeRemoteConfig();
}
loadConfig(RemoteConfig _remoteConfig) async
{  
    _link_sent_before_ads = _remoteConfig.getString('link_sent_before_ads').isEmpty ?  _link_sent_before_ads : int.tryParse(_remoteConfig.getString('link_sent_before_ads'));
 		 _max_send_limit_size = _remoteConfig.getString('max_send_limit_size').isEmpty ?  _max_send_limit_size : int.tryParse(_remoteConfig.getString('max_send_limit_size'));
}
  initializeRemoteConfig() async{
	RemoteConfig remoteConfig = await RemoteConfig.instance;
	try {
  	//set some default params in case of crash
  	await remoteConfig.setConfigSettings(RemoteConfigSettings(debugMode: false));
  	await remoteConfig.setDefaults(<String, dynamic>{
    	'service_api_conversion_1': 'https://ebook-converter.app/calibre/ebook-convert',
  	});
  	// Using default duration to force fetching from remote server.
  	await remoteConfig.fetch(expiration: const Duration(seconds: 0));
  	await remoteConfig.activateFetched();
	} on FetchThrottledException catch (exception) {
  	// Fetch throttled.
  	print(exception);
	} catch (exception) {
  	print('Unable to fetch remote config. Cached or default values will be used');
	}
	await this.loadConfig(remoteConfig);
  }
}

It can finally be used very simply in the following way:

//call this just first time in app initialization
await Configuration.instance.initializeRemoteConfig();
Print(Configuration.instance.maxSendLimitSize);
Last modified: 15 May 2020