common_interface

The contract between the multi_ads main plugin and the per-network ad plugins (google, unity, yodo, ironSource, facebook), plus the shared config, state and device models they all use.

import 'package:common_interface/common_interface.dart';

Everything public is exported from that single file.

Writing a network plugin

Extend NetworkInterface and report every result through AdCallbacks:

class MyNetworkAds extends NetworkInterface {
  @override
  Future<bool> init() async { /* start the SDK */ return true; }

  @override
  bool get isInitialized => _ready;

  @override
  bool isLoaded(AdsType type) => _cache[type] != null;

  @override
  void load(AdsType type, {AdCallbacks? callbacks}) { /* ... callbacks?.onLoaded?.call() */ }

  @override
  void show(AdsType type, {AdCallbacks? callbacks}) { /* ... onShown, onRewardEarned, onClosed */ }

  @override
  void loadAndShow(AdsType type, {AdCallbacks? callbacks}) { /* load, then show */ }

  @override
  Widget bannerAd() => const MyBanner();

  @override
  Widget nativeAd() => const MyNative();
}

Read your unit ids from the session:

final ids = AdSession.instance.idsFor(NetworkType.google);
final inter = ids?.interId;

Callback contract: a show that ends normally calls onClosed exactly once; reward ads call onRewardEarned or onRewardSkipped first; failures call onLoadFailed / onShowFailed with an AdFailure.

Building blocks

Area Types
Ads NetworkInterface, AdCallbacks, AdFailure, AdTarget, NetworkType, AdsType
Server config AdConfig, AdNetworkIds, RegisterAppParameters, Urls
Runtime state AdSession (config and networks), AdState (loader and tap rotation), ReviewPrompt
Device DeviceService, DeviceInfoModel, DeviceServerToken
Rewards Reward, RewardDetail, DatedRewards, CategoryRewards
UI helpers LoaderBuilder, RouteMethods, NativeAdContainerConfig, BuildContext size extensions
Storage KeyValueStore, SecureKeyValueStore, MemoryKeyValueStore

Server ad codes are "<network>.<adType>"; AdTarget.tryParse("2.1") is Unity rewarded.

Testing

Singletons expose reset() (AdSession, AdState), and DeviceService / ReviewPrompt take a KeyValueStore, so tests can use MemoryKeyValueStore instead of the platform keychain.

Upgrading from 1.x

See BREAKING_CHANGES.md.

Libraries

common_interface