Kotlin Multiplatform, Compose Multiplatform and Flutter

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Baseline date: 2026-10-07. This page is shorter than the platform pages, because the multiplatform tools reuse their APIs. The Kotlin Multiplatform section is at Kotlin Multiplatform, and the native details are in Android and iOS.

Coil 3 in Compose Multiplatform

Coil 3 is a Kotlin Multiplatform library: the same AsyncImage runs on Android, iOS, desktop and web in commonMain. A network fetcher artifact is required for each target (coil-network-ktor3 is the multiplatform choice, and coil-network-okhttp is Android and JVM only).

// commonMain
dependencies {
    implementation("io.coil-kt.coil3:coil-compose:3.6.3")
    implementation("io.coil-kt.coil3:coil-network-ktor3:3.6.3")
}
// plus one Ktor engine per platform: ktor-client-okhttp (Android), ktor-client-darwin (iOS), ktor-client-cio (desktop)
@Composable
fun Cover(url: String, blurhash: String?) {
    AsyncImage(
        model = url,
        contentDescription = null,
        placeholder = rememberBlurHashPainter(blurhash),   // from the KMP BlurHash library, below
        contentScale = ContentScale.Crop,
        modifier = Modifier.aspectRatio(2f / 3f),
    )
}

Cache sizes and the loader are configured with SingletonImageLoader.setSafe in common code or the platform entry points, see Coil getting started. Format support follows the platform: Skia decodes JPEG, PNG and WebP, and AVIF depends on the Skia build and the platform version, so serve WebP or JPEG when you are unsure.

BlurHash in Kotlin Multiplatform

vanniktech/blurhash (Maven Central, 0.3.0) decodes and encodes BlurHash in common code, and converts the result to a Compose ImageBitmap. Check its README for the exact functions in the version you install, then wrap the call in a remember:

@Composable
fun rememberBlurHashPainter(hash: String?): Painter? = remember(hash) {
    hash?.let { decodeBlurHashToImageBitmap(it, 32, 32) }?.let { BitmapPainter(it) }   // your wrapper over the library call
}

The algorithm is in the BlurHash page. A fully shared decoder avoids keeping separate Kotlin and Swift copies of the woltapp files.

Video with expect and actual

There is no shared multiplatform video player in the Compose Multiplatform core. The usual pattern is an expect composable with an actual per platform, each wrapping the native player:

// commonMain
@Composable
expect fun VideoPlayer(url: String, modifier: Modifier = Modifier)

// androidMain: Media3 ExoPlayer inside AndroidView, see the Media3 page
@Composable
actual fun VideoPlayer(url: String, modifier: Modifier) { /* AndroidView { PlayerView(it).apply { player = exoPlayer } } */ }

// iosMain: AVPlayerViewController inside UIKitViewController, see the AVFoundation page
@Composable
actual fun VideoPlayer(url: String, modifier: Modifier) { /* UIKitViewController(factory = { AVPlayerViewController() }) */ }

Both platforms play HLS natively, so one backend manifest serves both, see Media3 and AVFoundation. Libraries that provide a ready-made multiplatform player exist (search the KMP library index), so check their maintenance status first.

Flutter

Flutter (see the Flutter and Dart reference) has the same needs and equivalent packages:

  • cached_network_image shows a network image with a placeholder and a fade-in, backed by a disk cache and a memory cache. Use memCacheWidth to decode at the displayed size.

  • flutter_blurhash: BlurHash(hash: hash, image: url) shows the hash while the image loads, and can also be used as the placeholder of CachedNetworkImage.

  • video_player plays HLS through ExoPlayer and AVPlayer.

CachedNetworkImage(
  imageUrl: url,
  memCacheWidth: 640,
  placeholder: (context, url) => BlurHash(hash: blurhash),
  fit: BoxFit.cover,
)

Choose the variant by the logical size times the device pixel ratio, as in the other platform pages.

What is shared and what is not

A multiplatform app shares the decision and leaves the decoding to the platform. The decision is which variant to ask for, which is plain logic, and the platform part is what the device can decode and the pixel density.

flowchart TD subgraph Common["commonMain"] M["Cover and Variant models"] --> B["bestVariant: format, then width"] B --> UI["Compose: BoxWithConstraints and AsyncImage"] B --> E["expect fun supportsAvif"] end E --> AN["androidMain: SDK_INT at least 31"] E --> IO["iosMain: OS version at least 16"] UI --> C3["Coil 3 with Ktor: one loader, two caches"] C3 --> DK[("Disk cache in the temporary directory")]

The Compose part (AsyncImage, the loader, the caches) is shared as well, so the Android and iOS pages of this section apply with the platform-specific parts replaced by expect and actual declarations.

Worked example: the cover grid in common code

The running example is again the cover b81f with the variants of the backend pages. The models and the selection function live in commonMain, and only the answer to "can this device decode AVIF" is platform code:

// commonMain
@Serializable
data class Variant(val format: String, val width: Int, val url: String)

@Serializable
data class Cover(val id: String, val width: Int, val height: Int, val blurhash: String, val variants: List<Variant>)

expect fun supportsAvif(): Boolean

fun decodableFormats(): List<String> =
    if (supportsAvif()) listOf("avif", "webp", "jpeg") else listOf("webp", "jpeg")

fun bestVariant(variants: List<Variant>, pixelWidth: Int, formats: List<String> = decodableFormats()): Variant {
    for (format in formats) {
        val sorted = variants.filter { it.format == format }.sortedBy { it.width }
        val hit = sorted.firstOrNull { it.width >= pixelWidth } ?: sorted.lastOrNull()
        if (hit != null) return hit
    }
    error("no variant")
}

// androidMain
actual fun supportsAvif(): Boolean = android.os.Build.VERSION.SDK_INT >= 31

// iosMain
@OptIn(ExperimentalForeignApi::class)
actual fun supportsAvif(): Boolean = NSProcessInfo.processInfo.isOperatingSystemAtLeastVersion(
    cValue<NSOperatingSystemVersion> { majorVersion = 16; minorVersion = 0; patchVersion = 0 }
)

The composable reads the slot in pixels from the layout constraints, so it needs no density arithmetic:

@Composable
fun CoverTile(cover: Cover, modifier: Modifier = Modifier) {
    BoxWithConstraints(modifier.aspectRatio(cover.width.toFloat() / cover.height)) {
        val variant = remember(cover.id, constraints.maxWidth) { bestVariant(cover.variants, constraints.maxWidth) }
        AsyncImage(
            model = variant.url,
            contentDescription = null,
            placeholder = rememberBlurHashPainter(cover.blurhash),
            contentScale = ContentScale.Crop,
            modifier = Modifier.fillMaxSize(),
        )
    }
}

The same selection logic was evaluated in Node for the variants of the example (the Swift, Kotlin, TypeScript and Dart versions are the same few lines): a 160 dp tile on a phone with API 34 needs 420 pixels at 2.625x and gets w640.avif, while on API 29 the AVIF branch is skipped and the result is w640.webp. On iOS 17 at 3x the tile needs 480 pixels and gets w640.avif, and on iOS 15 w640.webp.

The loader is configured once for all targets, with explicit cache sizes. The disk cache directory comes from Okio, which Coil 3 uses for all its file access, and the same code runs on Android, iOS and the desktop:

@Composable
fun App() {
    setSingletonImageLoaderFactory { context ->
        ImageLoader.Builder(context)
            .memoryCache { MemoryCache.Builder().maxSizePercent(context, 0.25).build() }
            .diskCache {
                DiskCache.Builder()
                    .directory(FileSystem.SYSTEM_TEMPORARY_DIRECTORY / "covers")     // not available on the web targets
                    .maxSizeBytes(256L * 1024 * 1024)
                    .build()
            }
            .crossfade(true)
            .build()
    }
    CoverGrid()
}

setSingletonImageLoaderFactory has to run before the first image is requested, which is why it sits at the top of the root composable. The temporary directory can be cleared by the operating system, which is acceptable for a cache that is rebuilt from the CDN. Memory costs follow the same arithmetic as on the native pages: a 640 by 960 decoded image is 2.34 MiB, and the original 2400 by 3600 is 32.96 MiB.

Choosing the video player per platform

The expect composable of the previous section is the right abstraction for video as well, but there are three details that decide whether it works. The player must be released when the composable leaves the composition, on both platforms: in androidMain with DisposableEffect { onDispose { exoPlayer.release() } }, and in iosMain by pausing and dropping the AVPlayer. The size limits for cellular and for tiles that the other pages set (setMaxVideoSize and preferredMaximumResolution) belong inside each actual, because the two players name them differently. And the BlurHash and poster of the video are shared: the poster is an AsyncImage of the poster variant, shown until the user taps play, so that no player is created for a tile that nobody plays.

Flutter

The same example in Dart shows that the pieces are the same, with different names. The variant function repeats the logic of the other pages. Flutter’s image codec supports JPEG, PNG, GIF, WebP, BMP and WBMP, so the format list is WebP and JPEG unless a package adds a decoder for AVIF:

class Variant {
  const Variant(this.format, this.width, this.url);
  final String format;
  final int width;
  final String url;
}

Variant bestVariant(List<Variant> variants, int pixelWidth, {List<String> formats = const ['webp', 'jpeg']}) {
  for (final format in formats) {
    final sorted = variants.where((v) => v.format == format).toList()..sort((a, b) => a.width.compareTo(b.width));
    if (sorted.isEmpty) continue;
    return sorted.firstWhere((v) => v.width >= pixelWidth, orElse: () => sorted.last);
  }
  throw StateError('no variant');
}

The widget reads the slot from the layout, multiplies by the device pixel ratio, and gives the same number to memCacheWidth, so that the decoded image has the size of the slot. A dedicated CacheManager sets the disk limits:

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter_blurhash/flutter_blurhash.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';

final coverCache = CacheManager(
  Config('covers', stalePeriod: const Duration(days: 30), maxNrOfCacheObjects: 500),
);

class CoverTile extends StatelessWidget {
  const CoverTile({super.key, required this.cover});
  final Cover cover;

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (context, constraints) {
      final pixels = (constraints.maxWidth * MediaQuery.devicePixelRatioOf(context)).ceil();
      final variant = bestVariant(cover.variants, pixels);
      return AspectRatio(
        aspectRatio: cover.width / cover.height,
        child: CachedNetworkImage(
          imageUrl: variant.url,
          cacheManager: coverCache,
          memCacheWidth: pixels,
          fit: BoxFit.cover,
          placeholder: (context, url) => BlurHash(hash: cover.blurhash),
        ),
      );
    });
  }
}

memCacheWidth values for a 160 logical pixel tile were computed for common ratios: 320 at 2.0, 440 at 2.75 and 480 at 3.0. Setting memCacheWidth without the variant choice would still download whatever file the URL names, possibly the 2400 pixel original, so the two go together, the variant for the bytes on the network and memCacheWidth for the bytes in memory. To warm the cache for the next page, precacheImage(CachedNetworkImageProvider(url, cacheManager: coverCache), context) loads an image into the same cache before the tile exists, and it should be called with the URL of the variant that the tile will choose.