SDKsFlutter

Migrate to 1.0

Move a 0.x koah_flutter integration to the 1.0 API: renamed card constructors, per-axis sizing, and a sealed result type.

Prompt for coding agents

I use Koah's Flutter SDK (the koah_flutter package) on a 0.x version. Migrate my integration to the 1.0 API. Read https://docs.koahlabs.com/sdk/flutter/migration and follow its instructions.

What changes

Aspect0.x1.0
Card constructorKoahCard.withContext(adContext: ...)The unnamed KoahCard(adContext: ...)
Legacy query constructorKoahCard(query:, messageId:, ...)Removed. Build a KoahAdContext instead.
Warmed slotsKoahCard.fromCache(messageId: ...)KoahCard.fromCache(cacheKey: ...)
Imperative fetchprefetch, resolveAd, cancelPrefetch, processprefetchAd, requestAd, cancelPrefetchAd
KoahAdLoaderPrefetch-and-observe helperRemoved. Pair prefetchAd with KoahCard.fromCache.
SizingoverrideMaxWidth / overrideMaxHeight: int?width / height: KoahAxisSize (null = unbounded)
ResultKoahAdResult with a filled flagSealed: KoahAdFilled / KoahAdNoFill / KoahAdError
LoggingKoahLogLevel.verboseKoahLogLevel.debug (warning and info are new)
Format previewsKoahAdSize + KoahPreviewFormat.cardText, ...KoahAdSize removed; KoahPreviewFormat.cardTextMd, ...
Poll trackingKoah.trackPollVoted(...)Removed. Votes are recorded automatically.
ToolchainFlutter >=1.17.0Flutter >=3.29.2 (Dart ^3.7.2, unchanged)

Rename the card constructors

KoahCard.withContext is now the unnamed constructor, and KoahCard.fromCache takes cacheKey instead of messageId. Behavior is unchanged.

KoahCard.withContext(
  adContext: KoahAdContext.conversation(
    question: userMessage,
    answer: aiResponse,
  ),
  cacheKey: 'msg-1',
)
KoahCard.fromCache(messageId: 'msg-1')

Replace the legacy query constructor

The deprecated unnamed KoahCard(query:, messageId:, ...) constructor — and the legacy /query path behind it — is gone. Describe the surrounding content with a KoahAdContext and pass the old messageId as cacheKey.

KoahCard(
  query: userMessage,
  queryResponse: aiResponse,
  messageId: 'msg-1',
)

Replace the imperative trio

Koah.prefetch, Koah.resolveAd, and Koah.cancelPrefetch (positional query strings) become prefetchAd, requestAd, and cancelPrefetchAd (named parameters with a KoahAdContext). Koah.process is also removed — request with requestAd and render with a KoahCard. KoahAdLoader is removed too: pair prefetchAd with KoahCard.fromCache(cacheKey: ...).

await Koah.instance().prefetch(userMessage, aiResponse, 'msg-1');
final state = await Koah.instance().resolveAd(userMessage, aiResponse, 'msg-1');
Koah.instance().cancelPrefetch('msg-1');

Move to per-axis sizing

The max-only overrideMaxWidth / overrideMaxHeight knobs become width and height, each a KoahAxisSize built with a factory constructor: KoahAxisSize.fixed(dp), KoahAxisSize.range(min: ..., max: ...) (either bound may be omitted), or KoahAxisSize.fill(). null (the default) leaves the axis unbounded. Units are logical pixels, as before.

KoahCard.withContext(
  adContext: adContext,
  cacheKey: 'msg-1',
  overrideMaxWidth: 384,
  overrideMaxHeight: 320,
)

Switch over the sealed result

KoahAdResult is now a sealed class with three cases instead of a filled flag; its format field is gone.

final result = await Koah.instance().requestAd(
  adContext: adContext,
  cacheKey: 'msg-1',
);
if (result.filled) {
  // ad available to render
}

Update log levels

KoahLogLevel is reshaped from none / error / verbose to none / error / warning / info / debug. Replace verbose with debug; none stays the default.

Koah.instance(
  publisherId: 'your-publisher-id',
  logLevel: KoahLogLevel.verbose,
);

Update preview formats

KoahAdSize and the deprecated size: parameters are removed — bound the slot with width / height on the card, or dimensions: KoahDimensions(maxWidth: ..., maxHeight: ...) on the imperative calls. KoahPreviewFormat cases are now render formats:

0.x1.0
cardTextcardTextMd
cardImagecardImageMd
pollpollMd
—pollCtaMd (new)
expandableexpandableMd
rabbitHoleRemoved

Handle the new events

Not a rename, but it will surface as a compile error: KoahEvent gains two subclasses — InAppBrowserClosed and SlotTooSmall — so an exhaustive switch over KoahEvent without a wildcard must add the new cases. See Event handling.

Koah.trackPollVoted is removed with no replacement — poll votes are recorded automatically when the visitor taps an option.

Install 1.0

Update your pubspec.yaml to the stable release:

dependencies:
  koah_flutter: ^1.0.0

koah_flutter is now a Flutter plugin with a small iOS native component, so in an iOS app run pod install in your ios/ directory after upgrading (a plain flutter run also does this for you).

Need help upgrading? Email support@koahlabs.com.

Was this helpful?