sealed_countries 是一個 Flutter/Dart 套件,使用封閉類別提供完整的國家資料,確保類型安全與不可變性。它包含國家名稱、代碼和區域等資訊,非常適合需要可靠國家選擇或代碼查詢的應用程式。此套件設計了清晰且結構化的資料模型,支援 Android、iOS、Web、macOS、Windows 與 Linux 多個平台。其封閉類別方法可防止意外擴展,並提升程式碼可維護性。
適用情境
國家選擇器 UI 組件
國際化 (i18n) 設定
電話號碼或地址表單驗證
貨幣和語言區域映射
與國家資料的API整合
主要特色
基於密封類的國家資料模型
類型安全的國家列舉
支援所有主要平台
不可變且可預測的資料結構
完整的國家元資料
適合對象
開發多語言應用程式的開發者
表單驗證需要國家代碼
需要國家選擇介面的應用程式
注重資料建模類型安全的團隊
面向跨平台部署的項目
使用建議
需要理解 Dart 中的封閉類
僅限靜態國家資料(無即時更新)
由於產生的程式碼,建構大小可能會略微增加
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
Sealed World
A pure Dart, fully tested and ISO-driven ecosystem for the world's data in the form of compile-time, tree-shakable constant classes with a sealed origin.
[!TIP]
Flutter packages use world prefix, Dart packages use sealed prefix for core functionality and l10n prefix for localization maps.
This ecosystem follows a hierarchical structure with optional localization support. At the foundation are languages and scripts, providing core functionality across all packages. Building upon this, currencies extend the system, followed by countries. Each core package has an optional l10n companion that provides localization maps. The countries package serves as a bridge to Flutter, enabling the rendering of country flags, which the world_countries package uses to create UI components like country pickers with localized names and visual elements.
This section explains how the ecosystem handles SDK pinning, semantic versioning, and release cadence, and why this approach benefits users and contributors.
SDK Compatibility and Pinning
Pinning to the Dart version bundled with Flutter stable ensures local developer environments match CI, minimizing SDK mismatches and hard-to-reproduce issues. The Flutter SDK archive lists each Flutter stable release together with its bundled Dart version Flutter SDK archive.
Production packages target Dart stable rather than beta/dev, in line with Dart's guidance to use stable for building and deploying apps Get the Dart SDK.
Formatter and workspace changes introduced around Dart 3.7/3.8 can create large diffs when mixing pre/post language versions. Dart 3.8 includes a rewritten/updated formatter behavior; formatting changes apply when the package opts into the newer language version Announcing Dart 3.8, Breaking changes (formatter behavior >=3.8).
Semantic Versioning
Semantic Versioning is followed: MAJOR for breaking changes, MINOR for new features, PATCH for bug fixes Semantic Versioning.
Dart's pub ecosystem applies SemVer for resolution and documents conventions including pre-1.0 handling and "next breaking" logic Package versioning.
Release Cadence
Major releases: approximately once per year, potentially including breaking changes; aligned after Flutter/Dart stable cycles to reduce churn Semantic Versioning.
Minor releases: about once per month for feature additions (especially for Flutter-facing packages), without breaking changes Package versioning.
Patch releases: as needed for fixes and docs, with no API changes Package versioning.
Deprecated APIs are removed only after reaching end of life in a subsequent stable release cycle, consistent with Flutter's deprecation policy and examples across releases (e.g., removals after 3.7, 3.13, 3.19).
Migration guidance is linked in release notes for major removals, reducing friction and helping teams adopt changes in predictable windows Flutter breaking changes and migration guides.
Rationale
Aligning with Flutter stable's Dart ensures consistent environments across CI and contributors, reducing surprise failures and easing support Flutter SDK archive.
Benchmark & regression verification system
This package includes an automated benchmark system that runs on every release to detect performance regressions. Each version produces immutable JSON artifacts containing build metadata (APK size, toolchain versions, Android configuration) and runtime metrics (startup time, frame performance, memory and CPU usage, etc.).
[!TIP]
These artifacts are attached to GitHub Releases and committed to the repository, enabling historical comparison and transparent performance tracking across versions. The benchmark flow uses low-end physical ARM64 Android devices with Flashlight + Maestro for reproducible, device-driven testing.
To run benchmarks locally or learn more about the system, see the benchmarks documentation. Execute the shared CLI via dart run tools/bin/benchmarks.dart $package_name (or cd tools && dart run :benchmarks $package_name). Current targets include all Flutter packages. All benchmark data is immutable and versioned, ensuring full auditability and regression traceability.
[^1]: While sealed_languages technically depends on l10n_languages for localization, this is not part of its core functionality. The package primarily serves as the backbone for all sealed_* and world_* packages by providing typed locale classes and extensions that power localization maps across the entire ecosystem.