Skip to main content

VelocityAds

initialize()

Future<Map<String, dynamic>> initialize({
  required String appKey,
  bool debug = false,
})
Parameters:
  • appKey - Your application key for the current platform (required). iOS and Android use different keys.
  • debug - Enable debug logging (default: false)
Returns: {"success": true} on success Throws: VelocityAdsError on initialization failure, with code (numeric error code) and message (human-readable description)

setUserId()

void setUserId(String? userId)
Sets the user identifier for ad targeting. Call this before initialize() if the user ID is known at startup. Pass null to clear the user ID. Parameters:
  • userId - User identifier string, or null to clear

isInitialized()

Future<bool> isInitialized()
Returns: true if the SDK is initialized, false otherwise

setDoNotSell()

void setDoNotSell(bool flag)
Parameters:
  • flag - true to opt out of data sale, false to allow
Note: Only call in CCPA-regulated regions

setConsent()

void setConsent(bool flag)
Parameters:
  • flag - true if user consents, false if user denies
Note: Only call in GDPR-regulated regions

VelocityNativeAdRequest

Immutable ad request containing targeting parameters.
const VelocityNativeAdRequest({
  this.prompt,
  this.aiResponse,
  this.conversationHistory,
  this.additionalContext,
  this.adUnitId,
});
Parameters:
  • prompt - User’s query or prompt for contextual targeting
  • aiResponse - AI-generated response content for better targeting
  • conversationHistory - Previous conversation turns as ConversationMessage list
  • additionalContext - Extra context information (e.g., page content, user preferences)
  • adUnitId - Optional ad unit identifier for reporting

VelocityNativeAdViewRequest

Extends VelocityNativeAdRequest to request an SDK-rendered native ad view.
const VelocityNativeAdViewRequest({
  required this.size,
  this.adConfiguration,
  super.prompt,
  super.aiResponse,
  super.conversationHistory,
  super.additionalContext,
  super.adUnitId,
});
Parameters:
  • size - Required. The ad view size (VelocityAdViewSize.s, .m, or .l)
  • adConfiguration - Optional theming configuration for the ad view
  • All parameters from VelocityNativeAdRequest are also available

VelocityNativeAd

Instance-based ad object. Create with a request, call load(), then access ad data via data or the rendered widget.
VelocityNativeAd(VelocityNativeAdRequest adRequest);

Future<void> load();
void destroy();

NativeAdData? data;
Widget? get widget;
VelocityNativeAdListener? listener;
VelocityNativeAdViewListener? viewListener;
Methods:
  • load() - Loads the ad asynchronously. Populates data on success. For VelocityNativeAdViewRequest, also creates a rendered widget accessible via widget. Throws VelocityAdsError on failure.
  • destroy() - Releases native resources. Always call when the ad is no longer needed.
Properties:
  • data - NativeAdData? containing all ad creative fields after a successful load()
  • widget - Flutter Widget embedding the native ad view. Only available after load() when the request is a VelocityNativeAdViewRequest
  • listener - Optional VelocityNativeAdListener for data-only ad events. Set before calling load()
  • viewListener - Optional VelocityNativeAdViewListener for SDK-rendered view events. Set before calling load()

NativeAdData

Immutable object containing the ad creative fields. Available via VelocityNativeAd.data after a successful load.
FieldTypeDescription
idStringInternal SDK record identifier
adIdStringAd identifier used for impression/click tracking
titleStringAd headline
descriptionStringAd body text
callToActionStringCTA button text (e.g., “Learn More”)
advertiserNameStringAdvertiser / brand display name
sponsoredLabelString”Sponsored” label text
badgeLabelStringShort badge label (e.g., “ad”)
advertiserIconUrlStringBrand icon URL (small square thumbnail)
largeImageUrlString?Landscape hero image URL. null if not available
squareImageUrlString?Square (1:1) image URL. null if not available
clickUrlStringDestination URL when the ad is clicked
impressionUrlStringURL to track ad impressions

VelocityNativeAdListener

Abstract class for data-only ad lifecycle events. Use with VelocityNativeAdRequest.
abstract class VelocityNativeAdListener {
  void onAdLoaded(VelocityNativeAd ad) {}
  void onAdFailedToLoad(VelocityNativeAd ad, VelocityAdsError error) {}
  void onAdImpression(VelocityNativeAd ad) {}
  void onAdClicked(VelocityNativeAd ad) {}
}
All methods have default no-op implementations. Override only the ones you need.

VelocityNativeAdViewListener

Abstract class for SDK-rendered view ad lifecycle events. Use with VelocityNativeAdViewRequest.
abstract class VelocityNativeAdViewListener {
  void onAdLoaded(VelocityNativeAd ad, Widget adView) {}
  void onAdFailedToLoad(VelocityNativeAd ad, VelocityAdsError error) {}
  void onAdImpression(VelocityNativeAd ad) {}
  void onAdClicked(VelocityNativeAd ad) {}
}
The onAdLoaded callback receives both the VelocityNativeAd instance and the platform-rendered Widget (adView), identical to ad.widget.

VelocityAdViewSize

enum VelocityAdViewSize { s, m, l }
ValueHeightUse Case
VelocityAdViewSize.s50dpCompact banner-style ads
VelocityAdViewSize.m100dpStandard inline ads
VelocityAdViewSize.l300dpRich media ads with images

AdConfiguration

const AdConfiguration({
  this.colorScheme,
  this.adTypography,
  this.darkTheme,
});
Parameters:
  • colorScheme - Custom color palette for light and dark modes
  • adTypography - Custom text styles for ad elements
  • darkTheme - null to follow system, true/false to force a specific mode

AdColorScheme

const AdColorScheme({
  required AdColors light,
  required AdColors dark,
});

AdColors

Color tokens for ad rendering. Use AdColors.lightDefaults() or AdColors.darkDefaults() for built-in palettes, then copyWith() to override specific tokens.
TokenDescription
cardBackgroundBackground color of the ad card
sponsoredLabelText”Sponsored” label text color
titleTextAd title text color
descriptionTextAd description text color
brandTextAdvertiser/brand name text color
sponsoredBadgeBackgroundSponsored badge background
sponsoredBadgeTextSponsored badge text color
ctaBackgroundCall-to-action button background
ctaTextCall-to-action button text color
chevronIconTintChevron/arrow icon tint
brandIconBorderBrand icon border color

AdTypography

Typography tokens for ad text elements.
TokenDescription
brandNameAdvertiser/brand name text style
sponsoredLabel”Sponsored” label text style
sponsoredBadgeTextSponsored badge text style
titleAd title text style
descriptionAd description text style
ctaButtonCTA button text style

AdTextStyle

const AdTextStyle({
  required double fontSize,
  AdFontWeight? fontWeight,
});

AdFontWeight

Font weight constants for use with AdTextStyle.
ConstantWeight
AdFontWeight.normal400
AdFontWeight.medium500
AdFontWeight.semiBold600
AdFontWeight.bold700

ConversationMessage

ConversationMessage.user(String content);
ConversationMessage.assistant(String content);
Fields:
  • role - "user" or "assistant"
  • content - Message text