CuBid Flutter

The official Flutter plugin for CuBid advertising on Android and iOS. It supports banner, native, interstitial, and rewarded ads.

Valid CuBid credentials and placement IDs are required. Credentials are provided through official CuBid programs.

Requirements

  • Flutter 3.3 or newer
  • Dart 3.9 or newer
  • Android API 24 or newer
  • iOS 14.0 or newer

Installation

Add the plugin to your application:

dependencies:
  cubid_flutter: ^2.0.0

Then install dependencies:

flutter pub get

Initialization

final cubid = CubidFlutter();

await cubid.initialize(
  setId: 'YOUR_SET_ID',
  userId: 'YOUR_USER_ID',
  onInitialized: () {
    print('CuBid initialized');
  },
  onFailed: (CubidError error) {
    print('CuBid initialization failed: ${error.code} ${error.message}');
  },
);

Interstitial and rewarded lifecycle

Create the ad and load it in the same block. load, show and dispose are queued behind native creation, so they cannot overtake it and no await is needed in between:

final interstitial = cubid.createInterstitial(placementId: 'YOUR_PLACEMENT_ID');

interstitial.events.listen((event) {
  switch (event.type) {
    case CubidInterstitialEventType.loaded:
      interstitial.show();
    case CubidInterstitialEventType.failed:
      print('${event.error?.code}: ${event.error?.message}');
    default:
      break;
  }
});

interstitial.load(); // Safe immediately after creation.

CubidRewarded behaves identically.

Two things worth knowing:

  • Initialization is the one ordering you enforce yourself. Create ads only after initialize reports success, either from its onInitialized callback or by checking cubid.initializationStatus == CubidInitState.initialized.
  • The load() future resolving means the platform accepted the request, not that an ad is available. The outcome always arrives on events as loaded or failed. Events emitted before you subscribe are buffered, so subscribing after calling load() still delivers them.

ready is available when you want to observe creation itself, but awaiting it before load() is unnecessary:

await interstitial.ready; // Throws if the native instance could not be created.

Call dispose() when you are done. It is safe at any time, including while creation is still in flight:

@override
void dispose() {
  interstitial.dispose();
  super.dispose();
}

Errors

All asynchronous CuBid SDK failures are exposed as CubidError:

class CubidError {
  final int? code;
  final String message;
}

Native ad failures use the same type:

CubidNativeAd(
  placementId: 'YOUR_PLACEMENT_ID',
  factoryId: 'default',
  onFailed: (error) {
    print('${error.code}: ${error.message}');
  },
)

Interstitial and rewarded streams expose errors on their events:

interstitial.events.listen((event) {
  final error = event.error;
  if (error != null) {
    print('${error.code}: ${error.message}');
  }
});

code can be null only when an older native plugin or a native initialization callback supplies a message without a recognizable CuBid code.

See the complete application in example/.

For onboarding and SDK documentation, visit the CuBid project.