Initialize the Flutter SDK
Rokt's SDK for Flutter applications can be used by Rokt partners to display overlay or embedded placements, or by Rokt advertisers to record conversions for campaigns. The Rokt SDK for Flutter is deployed to pub.dev .
All use cases of the SDK will follow the same initial steps to integrate and initialize the SDK in your application. At a high level, these steps are:
- Integrating the SDK into your Flutter application
- Configuring for Android applications
- Initialize the Rokt SDK
Following these steps, the execute
method of the SDK can then be used in various ways to suit the required use case.
Integrate the SDK into your Flutter application
To integrate the SDK into your Flutter application, you need to:
- Add the
rokt_sdk: ^4.3.0
to dependencies ofpubspec.yaml
file. - Run
Flutter Pub Get
via terminal or Android Studio.
Configure for Android
To configure the Rokt Flutter SDK for Android applications, you need to:
- Set the
minSdkVersion
and enablemultidex
inandroid/app/build.gradle
:
android {
defaultConfig {
minSdkVersion 21
multidexEnabled true
}
}
This means that app will only be available for users that run Android SDK 19 or higher.
- Include appcompat dependency implementation
implementation 'androidx.appcompat:appcompat:x.x.x'
The theme of android/app should extend from AppCompat theme family, example:
<style name="NormalTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"/>
Initialize the Rokt SDK for Flutter
Initialize the Rokt SDK for Flutter prior to using it. We recommend calling the initialize
method early in the application.
Contact Rokt for the Rokt Account ID associated with your account. In order to test your integration, you can use the tes account ID below. Remember, however, that this needs to be replaced by your unique Rokt Account ID before launching.
Test Rokt Account ID: 222
import 'package:rokt_sdk/rokt_sdk.dart';
// The following will reveal a demo integration. To view your integration:
// 1) Replace the integration test tag ID (222) with your unique Rokt Tag ID
// 2) Replace 1.0.0 with the application version
RoktSdk.initialize('222', appVersion: '1.0.0');
Initializing with Fonts
This functionality is supported from version 4.2.0 of the Rokt Flutter SDK.
Instead of or in addition to supplying your desired fonts on One Platform, you may choose to utilize the fonts already bundled with your application. This carries the advantage of removing the potential for fonts to be downloaded at initialization time, reducing network utilization and the chances of download errors.
You must provide the font postscript names and filepaths if you wish the utilize this functionality. The postscript names should match those being used in your layout, please check with your account manager if you are unsure.
Your fonts should be defined in your pubspec.yaml
to utilize this functionality. You should pass the same filepath as defined in your pubspec.yaml
for each font. See https://docs.flutter.dev/cookbook/design/fonts#declare-the-font-in-the-pubspecyaml-file for more details.
import 'package:rokt_sdk/rokt_sdk.dart';
RoktSdk.initialize('222', appVersion: '1.0.0', fontFilePathMap: {"Arial-Bold", "fonts/Arial-Bold.ttf"});
Debugging
Use the RoktSdk.setLoggingEnabled(enable: true);
API to enable debug logs from the Rokt SDK.
Next steps
Your next steps depend on the use case of your integration. Check out these resources for more information: