Better I18NBetter I18N
Flutter

API Reference

Complete API documentation for the better_i18n Flutter SDK.

Complete API reference for the better_i18n Flutter/Dart SDK.

BetterI18nProvider

The top-level widget. Manages the BetterI18nController lifecycle and provides translations to all descendant widgets via BetterI18nScope.

BetterI18nProvider(
  project: 'acme/app',
  defaultLocale: 'en',
  storage: SharedPrefsStorage(),
  loadingBuilder: (_) => const CircularProgressIndicator(),
  child: const MyApp(),
)

Props

PropTypeRequiredDefaultDescription
projectStringYesProject identifier in "org/project" format
defaultLocaleStringYesFallback locale used when no locale is set
childWidgetYesRoot widget of your app
localeString?NonullExternally controlled locale (e.g., from a Cubit/BLoC)
cdnBaseUrlString?Nohttps://cdn.better-i18n.comCDN URL override
ttlint?No300000Memory cache TTL in milliseconds (5 min)
timeoutint?No10000CDN fetch timeout in milliseconds
retryint?No1Number of retry attempts on CDN failure
storageTranslationStorage?NonullPersistent storage adapter — use SharedPrefsStorage()
staticDataMap<String, Messages>?NonullBundled fallback translations for airplane mode first launch
loadingBuilderWidgetBuilder?NonullWidget shown while translations are loading (initial load only)
errorBuilderWidget Function(BuildContext, Object)?NonullWidget shown when a fatal error occurs

When locale is set externally (e.g., from a Cubit), BetterI18nProvider detects changes via didUpdateWidget and calls controller.setLocale() automatically.


BuildContext Extensions

Available on any BuildContext below BetterI18nProvider in the widget tree.


BetterI18nController

Manages i18n state — locale, messages, and languages. Extends ChangeNotifier so widgets rebuild when state changes.

final controller = BetterI18nController(
  config: const I18nConfig(
    project: 'acme/app',
    defaultLocale: 'en',
  ),
  initialLocale: 'tr',
);
await controller.initialize();

Constructor

ParameterTypeRequiredDescription
configI18nConfigYesCore configuration
initialLocaleString?NoStarting locale — defaults to config.defaultLocale

Getters

GetterTypeDescription
localeStringCurrent active locale
messagesMessages?Loaded translation messages (null until ready)
languagesList<LanguageOption>Available languages from CDN manifest
isLoadingboolWhether translations are currently loading
isReadyboolWhether the controller is initialized and ready
errorObject?Last error that occurred during loading, if any

Methods


I18nCore

The pure Dart core engine — no Flutter dependency. Implements the 4-tier fallback chain. Used internally by BetterI18nController.

final core = I18nCore(
  config: NormalizedConfig(
    project: 'acme/app',
    defaultLocale: 'en',
    cdnBaseUrl: 'https://cdn.better-i18n.com',
    manifestCacheTtlMs: 300000,
    timeout: 10000,
    retry: 1,
  ),
);

Methods


BetterI18nScope

Low-level InheritedNotifier that provides BetterI18nController to the widget tree. Used internally by BetterI18nProvider — use directly only for testing or advanced scenarios.

BetterI18nScope(
  controller: myController,
  child: MyWidget(),
)

Static Methods


Types


Storage


Testing Utilities

On this page