Using Firebase Remote Config
Once installed, you can access the firebase_remote_config
plugin by importing
it in your Dart code:
Before using Firebase Remote Config, you must first have ensured you have initialized FlutterFire.
To create a new Firebase Remote Config instance, call the instance
getter on FirebaseRemoteConfig
:
By default, this allows you to interact with Firebase Remote Config using the default Firebase App used whilst installing FlutterFire on your
platform. If however you'd like to use a secondary Firebase App, use the instanceFor
method:
Defaults
Firebase Remote Config default parameters allows your application to startup without the need to make a
network call. To set the default parameters call the setDefaults()
method on your FirebaseRemoteConfig
instance:
Fetching and activating
Only when default parameters are no longer sufficient updates to the Remote Config template should be made
in the Firebase console or via the Admin SDK. Use the fetchAndActivate()
method on your FirebaseRemoteConfig
instance:
The fetchAndActivate()
combines the operations of the fetch()
and activate()
methods which can be used separately
if needed.
Get/Use parameters
Whether using default or fetched parameters, you can fetch the parameter values using the available getters:
Other getters include: getBool()
, getInt()
, getDouble()
, getValue()
.
Settings
Since fetching involves network calls Remote Config allows you to specify how long cached parameters are valid and
how long a fetch should wait before timing out. These settings can be specified using the setConfigSettings()
method on your FirebaseRemoteConfig
instance:
The above snippet specifies that a fetch will wait up to 10 seconds before timing out and fetch parameters will be
cached for a maximum of 1 hour before being considered stale and going to the server on the next fetch()
call.