Keep the Klarna instance for as long as Klarna features in your app need to share the same native session. Calling Klarna.initialize again with an equivalent configuration reuses the same instance until it is disposed.
Handle return URLs
Return URLs are not used by On-site Messaging placements directly. They are required by the shared Dart configuration and support other Klarna features that can open external flows.
When a URL returns to your app, offer it to the Core SDK:
DART
1
2
final handled = await Klarna.handleReturnUrl(url);
On iOS, this dispatches the URL to the native Klarna SDK. On Android, it currently returns false.
Render a messaging placement
Add KlarnaMessagingPlacementView to your widget tree:
The amount is expressed in minor units. For example, 19900 represents EUR 199.00.
The placement starts with a fallback height, adopts the height reported by the native SDK, and collapses when no content is available. You do not need to set an explicit height.
To render a compact badge, use the badge configuration:
When checkout values change, rebuild the widget with a new configuration. The SDK updates the native placement when its amount, currency, placement type, theme, or Klarna instance changes.
Error handling
Initialization can throw KlarnaSDKError. Placement errors are delivered through onError:
DART
1
2
3
4
5
6
7
try {
final klarna = await Klarna.initialize(configuration);
// Render the placement with this instance.
} on KlarnaSDKError catch (error) {
debugPrint('${error.name}: ${error.message}');
}
KlarnaSDKError provides name, message, and an optional cause.
The placement widget unregisters its native callbacks automatically when removed from the widget tree. Dispose the shared session when it is no longer needed:
DART
1
2
await klarna.dispose();
Parameters
KlarnaConfiguration
Parameter
Type
Required
Description
clientId
String
Yes
The client identifier from the Klarna Partner Portal. If the integration is done by a PSP/distribution partner, use the distribution partner's own client ID.
appReturnUrl
String
Yes
URL used to return to the app from external flows. On iOS, its scheme must be registered in Info.plist.
accountId
String?
No
Optional Klarna account identifier.
locale
String?
No
Session locale, for example en-US.
Placement configuration
Parameter
Type
Required
Description
instance
Klarna
Yes
Shared session returned by Klarna.initialize.
configuration
KlarnaMessagingPlacementConfiguration
Yes
Placement type, amount, currency, and optional theme.
onError
ValueChanged<KlarnaSDKError>?
No
Called when the placement reports an asynchronous error.