Flutter - Adapty SDK Installation and configuration
- v3.2.x and up (current)
- Up to v2.x (legacy)
Adapty SDK includes two key modules for seamless integration into your mobile app:
- Core Adapty: This essential SDK is required for Adapty to function properly in your app.
- AdaptyUI: This module is required if you’re using the Adapty Paywall Builder—a no-code, user-friendly tool for creating cross-platform paywalls. With a visual constructor right in the dashboard, you can build paywalls that run natively on devices and are designed to deliver high performance with minimal effort. The module is installed automatically with the Adapty SDK, but you can leave it deactivated if you don’t need it.
Go through the release checklist before releasing your app
Before releasing your application, make sure to carefully review the Release Checklist thoroughly. This checklist ensures that you've completed all necessary steps and provides criteria for evaluating the success of your integration.
Install Adapty SDKs
-
Add Adapty and AdaptyUI to your
pubspec.yaml
file:pubspec.yamldependencies:
adapty_flutter: ^3.2.1 -
Run:
Bashflutter pub get
Configure Adapty SDKs
You only need to configure the Adapty SDK once, typically early in your app's lifecycle.
Activate Adapty module of Adapty SDK
-
Import Adapty SDKs in your application in the following way:
Dartimport 'package:adapty_flutter/adapty_flutter.dart';
-
Activate Adapty SDK with the following code:
Darttry {
await Adapty().activate(
configuration: AdaptyConfiguration(apiKey: 'YOUR_API_KEY')
..withLogLevel(AdaptyLogLevel.debug)
..withObserverMode(false)
..withCustomerUserId(null)
..withIpAddressCollectionDisabled(false)
..withIdfaCollectionDisabled(false),
);
} catch (e) {
// handle the error
}
Parameters:
Parameter | Presence | Description |
---|---|---|
PUBLIC_SDK_KEY | required | The key you can find in the Public SDK key field of your app settings in Adapty: App settings-> General tab -> API keys subsection |
withLogLevel | optional | Adapty logs errors and other crucial information to provide insight into your app's functionality. There are the following available levels:
|
withObserverMode | optional | A boolean value controlling Observer mode. Turn it on if you handle purchases and subscription status yourself and use Adapty for sending subscription events and analytics. The default value is 🚧 When running in Observer mode, Adapty SDK won't close any transactions, so make sure you're handling it. |
withCustomerUserId | optional | An identifier of the user in your system. We send it in subscription and analytical events, to attribute events to the right profile. You can also find customers by customerUserId in the Profiles and Segments menu. |
withIdfaCollectionDisabled | optional | Set to the user IP address sharing. The default value is For more details on IDFA collection, refer to the Analytics integration section. |
withIpAddressCollectionDisabled | optional | Set to The default value is |
Activate AdaptyUI module of Adapty SDK
You need to configure the AdaptyUI module only if you plan to use Paywall Builder and have installed AdaptyUI module:
try {
final mediaCache = AdaptyUIMediaCacheConfiguration(
memoryStorageTotalCostLimit: 100 * 1024 * 1024, // 100MB
memoryStorageCountLimit: 2147483647, // 2^31 - 1, max int value in Dart
diskStorageSizeLimit: 100 * 1024 * 1024, // 100MB
);
await AdaptyUI().activate(
configuration: AdaptyUIConfiguration(mediaCache: mediaCache),
observer: <AdaptyUIObserver Implementation>,
);
} catch (e) {
// handle the error
}
Please note that AdaptyUI configuration is optional, you can activate AdaptyUI module without its config. However, if you use the config, all parameters are required in it.
Parameters:
Parameter | Presence | Description |
---|---|---|
memoryStorageTotalCostLimit | required | Total cost limit of the storage in bytes. |
memoryStorageCountLimit | required | The item count limit of the memory storage. |
diskStorageSizeLimit | required | The file size limit on disk of the storage in bytes. 0 means no limit. |
Adapty comprises two crucial SDKs for seamless integration into your mobile app:
- Core AdaptySDK: This is a fundamental, mandatory SDK necessary for the proper functioning of Adapty within your app.
- AdaptyUI SDK: This optional SDK becomes necessary if you use the Adapty Paywall builder: a user-friendly, no-code tool for easily creating cross-platform paywalls. These paywalls are built in a visual constructor right in our dashboard, run entirely natively on the device, and require minimal effort from you to create something that performs well.
Please consult the compatibility table below to choose the correct pair of Adapty SDK and AdaptyUI SDK.
Adapty SDK version | AdaptyUI SDK version |
---|---|
2.9.3 | 2.1.0 |
2.10.0 | 2.1.1 |
2.10.1 | 2.1.2 |
2.10.3 | 2.1.3 |
Install Adapty SDKs
-
Add Adapty and AdaptyUI to your
pubspec.yaml
file:pubspec.yamldependencies:
adapty_flutter: ^2.10.3
adapty_ui_flutter: ^2.1.3 -
Run:
Bashflutter pub get
-
Import Adapty SDKs in your application in the following way:
Dartimport 'package:adapty_flutter/adapty_flutter.dart';
import 'package:adapty_ui_flutter/adapty_ui_flutter.dart';
Configure Adapty SDKs
The configuration of the Adapty SDK for Flutter slightly differs depending on the mobile operating system (iOS or Android) you are going to release it for.
Configure Adapty SDKs for iOS
Create Adapty-Info.plist
and add it to your project. Add the flag AdaptyPublicSdkKey
in this file with the value of your Public SDK key.
<dict>
<key>AdaptyPublicSdkKey</key>
<string>PUBLIC_SDK_KEY</string>
<key>AdaptyObserverMode</key>
<false/>
</dict>
Parameters:
Parameter | Presence | Description |
---|---|---|
AdaptyPublicSdkKey | required | The key you can find in the Public SDK key field of your app settings in Adapty: App settings-> General tab -> API keys subsection |
AdaptyObserverMode | optional | A boolean value controlling Observer mode. Turn it on if you handle purchases and subscription status yourself and use Adapty for sending subscription events and analytics. At any purchase or restore in your application, you'll need to call 🚧 When running in Observer mode, Adapty SDK won't close any transactions, so make sure you're handling it. |
idfaCollectionDisabled | optional | A boolean parameter, that allows you to disable IDFA collection for your iOS app. The default value is For more details, refer to the Analytics integration section. |
Configure Adapty SDKs for Android
-
Add the
AdaptyPublicSdkKey
flag into the app’sAndroidManifest.xml
(Android) file with the value of your Public SDK key.AndroidManifest.xml<application ...>
...
<meta-data
android:name="AdaptyPublicSdkKey"
android:value="PUBLIC_SDK_KEY" />
<meta-data
android:name="AdaptyObserverMode"
android:value="false" />
</application>Required parameters:
Parameter | Presence | Description |
---|---|---|
PUBLIC_SDK_KEY | required | Contents of the Public SDK key field in the App Settings -> General tab in the Adapty Dashboard. SDK keys are unique for every app, so if you have multiple apps make sure you choose the right one. Make sure you use the Public SDK key for Adapty initialization, since the Secret key should be used for server-side API only. |
AdaptyObserverMode | optional | A boolean value that is controlling Observer mode . Turn it on if you handle purchases and subscription status yourself and use Adapty for sending subscription events and analytics. The default value is 🚧 When running in Observer mode, Adapty SDK won't close any transactions, so make sure you're handling it. |
AdaptyIDFACollectionDisabled | optional | A boolean parameter, that allows you to disable IDFA collection for your app. The default value is For more details, refer to the Analytics integration section. |
-
In your application, add:
Flutterimport 'package:adapty_flutter/adapty_flutter.dart';
-
Activate Adapty SDK with the following code:
Fluttertry {
Adapty().activate();
} on AdaptyError catch (adaptyError) {}
} catch (e) {}
Please keep in mind that for paywalls and products to be displayed in your mobile application, and for analytics to work, you need to display the paywalls and, if you're using paywalls not created with the Paywall Builder, handle the purchase process within your app.
Set up the logging system
Adapty logs errors and other crucial information to provide insight into your app's functionality. There are the following available levels:
Level | Description |
---|---|
error | Only errors will be logged. |
warn | Errors and messages from the SDK that do not cause critical errors, but are worth paying attention to will be logged. |
info | Errors, warnings, and serious information messages, such as those that log the lifecycle of various modules will be logged. |
verbose | Any additional information that may be useful during debugging, such as function calls, API queries, etc. will be logged. |
You can set logLevel
in your app before configuring Adapty.
try {
await Adapty().setLogLevel(AdaptyLogLevel.verbose);
} on AdaptyError catch (adaptyError) {
} catch (e) {}
Read checklist before releasing the app
Before releasing your application, go through the Release Checklist to ensure that you have completed all the steps, and also check the success of the integration using the criteria for assessing its success.