Remote configuration for Flutter apps
Remote Config enables you to change the behavior or appearance of the app by making changes to the server side values. To add the parameters and conditions in the Remote Config UI, refer to the User Guide.
Add the remote config SDK to your app
- Before your begin, make sure that Apptics is integrated into your project by following the Integration Guide.
- Use the below method to fetch value for a param. In the below snippet, the color param is fetched from the Apptics console and is then used to show the alert popup.
Copiedimport 'package:apptics_flutter/remoteconfig/apptics_remote_config.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
getRemoteConfigData(BuildContext context) async {
// Use the below method to fetch value for a param.
String? stringValue = await AppticsRemoteConfig.instance.getStringValue('color'); // params need to config in web console.
if (stringValue != null) {
print("stringValue $stringValue");
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(stringValue),
alignment: Alignment.center,
);
},
);
} else {
print("No data available");
}
}
@override
Widget build(BuildContext context) {
getRemoteConfigData(context);
// return your widget;
}
}
Show full
Show less
- getStringValue accept three params.
CopiedFuture<String?> getStringValue(String key, { bool coldFetch = false, bool fallbackWithOfflineValue = false,})
- key [string] - the name of the param configured in the web console.
- 'coldFetch' [bool] getStringValue has a cache mechanism which will prevent frequent network calls. If coldFetch is enabled, getStringValue fetches from network ignoring the cache mechanisms. Only three calls to the network are allowed per minute. If this threshold breaks, the method will return Null or fallback to offline value.
- 'fallbackWithOfflineValue' [boolean] - If enabled, getStringValue will return the previously fetched value incase of Network failures.
Set custom criteria
- Use the below method to set the custom condition criteria for the device.
CopiedAppticsRemoteConfig.instance.setCustomConditionValue("ConditionKey", "Criteria")