FlagCdn

data class FlagCdn(val shape: FlagImageShape = FlagImageShape.Waving, val format: FlagImageFormat = FlagImageFormat.Png, val fallbackToEmoji: Boolean = true, val baseUrl: String = DEFAULT_BASE_URL) : CountryFlagSource(source)

Flag images from flagcdn.com — the same artwork on every platform, for every country in the dataset, Kosovo included.

Images are fetched at the smallest size that is sharp at the screen's density and cached in memory and on disk, so each flag downloads once. While a flag loads — and whenever it cannot, offline for instance — the emoji flag stands in, so the picker never shows an empty slot.

Flags are fetched from a third-party CDN, which sees the device's IP address. For apps that must not make that request, use Emoji, or point baseUrl at a mirror you host with the same layout.

Constructors

Link copied to clipboard
constructor(shape: FlagImageShape = FlagImageShape.Waving, format: FlagImageFormat = FlagImageFormat.Png, fallbackToEmoji: Boolean = true, baseUrl: String = DEFAULT_BASE_URL)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The CDN root, without a trailing slash.

Link copied to clipboard

Show the emoji flag while an image loads and when it fails. Off shows a quiet placeholder instead — for a design that must never mix the two kinds of artwork.

Link copied to clipboard

The image format. See FlagImageFormat for which shapes offer which formats.

Link copied to clipboard

The three flagcdn shapes: waving at 4:3, or the flag's original proportions at a common width or a common height. See FlagImageShape.

Functions

Link copied to clipboard
fun urlFor(iso2Code: String, widthPx: Int, heightPx: Int): String

The address of iso2Code's flag, at the smallest size that covers widthPx by heightPx pixels.