Skip to content
Open Portal

Flutter SDK

Integrate Appylar in your Flutter app.

Applies to Appylar v1.0

The Appylar Flutter SDK (v1.0.0) is the Dart equivalent of the Android and iOS SDKs: request and display ads, and promote your app across the network through campaigns. It's a pure-Dart package — no platform channels, no native bridge and no third-party dependencies. This page covers the complete public API.

You need an app key (app_live_…) from the portal before you start. See Getting Started.

#Requirements

Flutter3.x (Dart 3)
PlatformsAndroid and iOS targets
DistributionGit (pub.dev listing in preparation)

#Installation

The package is being prepared for pub.dev. Until it's published, depend on it from Git:

dependencies:
  appylar:
    git:
      url: https://github.com/appylar/appylar-flutter-sdk.git

Once published, this becomes:

dependencies:
  appylar: ^1.0.0

Then run flutter pub get and import it:

import 'package:appylar/appylar.dart';

#initialize()

Call initialize once at app startup. It's non-blocking and idempotent.

Appylar.initialize("app_live_xxx");

#Configuration

Appylar.initialize(
  "app_live_xxx",
  config: const AppylarConfig(testMode: false, logLevel: LogLevel.info),
);
  • testMode — sandbox with deterministic test ads. Default false.
  • logLevelLogLevel.none, .error, .warn, .info (default) or .debug.

initialize throws ArgumentError if the app key is empty.

Appylar.setConsent(const Consent(gdprConsent: true, childDirected: false));
  • gdprConsent — consent for personalized advertising.
  • childDirected — COPPA / families mode.

The SDK does not show a consent dialog — collect consent with your own CMP and pass the result to setConsent.

BannerWidget is a normal Flutter widget. Drop it into your tree and it loads and renders itself — there's no load() call and no auto-refresh. Give it a height with your own layout.

import 'package:appylar/appylar.dart';
import 'package:flutter/material.dart';

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        const Expanded(child: /* your content */ SizedBox()),
        SizedBox(
          height: 50,
          child: BannerWidget(
            listener: BannerListener(
              onLoaded: () {},
              onFailedToLoad: (error) {}, // e.g. AdError.noFill
            ),
          ),
        ),
      ],
    );
  }
}

If you need a banner outside the widget tree, Appylar.createBanner() returns a BannerAd you drive with load().

#Interstitial

import 'package:appylar/appylar.dart';

late final InterstitialAd interstitial;

void preloadAd(BuildContext context) {
  interstitial = Appylar.createInterstitial(
    listener: InterstitialListener(
      onLoaded: () => interstitial.show(context),
      onFailedToLoad: (error) {},
      onShown: () {},
      onDismissed: () {},
    ),
  );
  interstitial.load();
}

show([context]) presents a loaded ad. It's a no-op if nothing is loaded or one is already showing; showing in an invalid state delivers AdError.invalidState. The ad is consumed on dismiss — reload before showing again.

#Listeners

Both listeners take optional callbacks, so you provide only what you need.

ListenerCallbackWhen
BannerListeneronLoadedBanner loaded
onFailedToLoad(error)Load failed
InterstitialListeneronLoadedAd ready
onFailedToLoad(error)Load failed
onShownAd presented
onDismissedAd closed

#Errors

Failures arrive through the onFailedToLoad callbacks. AdError has exactly four values:

ValueMeaning
AdError.noFillNo eligible ad right now — expected, not a bug
AdError.networkErrorNetwork or server error
AdError.notInitializedAppylar.initialize hasn't run, or the key is invalid
AdError.invalidStatee.g. showing an interstitial before a successful load

#Lifecycle

  1. Appylar.initialize(appKey) once at startup; setConsent as early as possible.
  2. Banner: drop BannerWidget into the tree (it self-loads); it stops when removed.
  3. Interstitial: createInterstitial()load()show(context) on onLoaded.

One ad at a time; no preloading of multiple ads and no auto-refresh in v1.

#Sample app

The Flutter SDK repository ships a complete example app that initializes the SDK, collects consent, and shows a banner and an interstitial with real loading, loaded, no-fill and error states. It uses only the public API and mirrors the Android and iOS samples. Find it under example/ in the Flutter SDK repository.

#Best practices

  • Initialize at launch so a token is ready before the first request.
  • Keep a reference to interstitials until they're dismissed.
  • Treat AdError.noFill as normal.
  • Use LogLevel.debug during integration, LogLevel.info in production.

#Distribution store

The SDK detects whether it's running on Android or iOS at runtime and reports it on every ad request, so Appylar routes each ad's click-through to the matching store listing — Google Play or the App Store. If an Android build ships to a different store, declare it:

Appylar.initialize(
  "app_live_xxx",
  config: const AppylarConfig(store: AppylarStore.amazonAppstore),
);

AppylarStore covers googlePlay, appleAppStore, amazonAppstore, huaweiAppGallery and samsungGalaxyStore. You only need it for non-default Android stores. See the serving protocol for how routing works.