Using Network Specific APIs

Mediation networks may provide APIs in their own Android and iOS SDKs that allow for further ads customization. You can call these APIs from dart code by using a platform channel.

The following sample shows you how to call privacy APIs in AppLovin's Android and iOS SDKs from Dart.

Create a method channel in dart

In your dart code, create a method channel:

/// Wraps a method channel that makes calls to AppLovin privacy APIs.
class MyMethodChannel {
  final MethodChannel _methodChannel =

  /// Sets whether the user is age restricted in AppLovin.
  Future<void> setAppLovinIsAgeRestrictedUser(bool isAgeRestricted) async {
    return _methodChannel.invokeMethod(
        'isAgeRestricted': isAgeRestricted,

  /// Sets whether we have user consent for the user in AppLovin.
  Future<void> setHasUserConsent(bool hasUserConsent) async {
    return _methodChannel.invokeMethod(
        'hasUserConsent': hasUserConsent,

Modify your Android code

Set up a method channel to make API calls to the AppLovin SDK in Android:

public class MainActivity extends FlutterActivity {
  private static final String CHANNEL_NAME =

  public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {

    // Set up a method channel for calling APIs in the AppLovin SDK.
    new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
          (call, result) -> {
            switch (call.method) {
              case "setIsAgeRestrictedUser":
                AppLovinPrivacySettings.setIsAgeRestrictedUser(call.argument("isAgeRestricted"), context);
              case "setHasUserConsent":
                AppLovinPrivacySettings.setHasUserConsent(call.argument("hasUserConsent"), context);

Modify your iOS code

Set up a method channel to make API calls to the AppLovin SDK in iOS:

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];

  // Set up a method channel for calling methods in 3P SDKs.
  FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;

  FlutterMethodChannel* methodChannel = [FlutterMethodChannel
  [methodChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
    if ([call.method isEqualToString:@"setIsAgeRestrictedUser"]) {
      [ALPrivacySettings setIsAgeRestrictedUser:call.arguments[@"isAgeRestricted"]];
    } else if ([call.method isEqualToString:@"setHasUserConsent"]) {
      [ALPrivacySettings setHasUserConsent:call.arguments[@"hasUserConsent"]];
    } else {

Use your MethodChannel in Dart

Now you can use your MyMethodChannel to call AppLovin privacy APIs from Dart:

/// An example widget for the home page of your app.
class HomePage extends StatefulWidget {
  _HomePageState createState() => _HomePageState();

class _HomePageState extends State<HomePage> {
  // Keep a reference to your MyMethodChannel.
  static MyMethodChannel platform = MyMethodChannel();
  void initState() {

  Future<void> _updateAppLovinSettingsAndLoadAd() async {
    // Update the AppLovin settings before loading an ad.
    await platform.setAppLovinIsAgeRestrictedUser(true);
    await platform.setHasUserConsent(false);
  void _loadAd() {
    // TODO: Load an ad.

  Widget build(BuildContext context) {
    // TODO: Build your widget.

More details on the APIs supported by other networks can be found in the Android and iOS documentation.