ActiveLocalizationDelegate class
Application-owned locale loading that composes with existing Flutter delegates.
In MaterialApp add this delegate alongside Flutter SDK delegates; switch locale using app-owned state. The gallery includes asset catalogs, context.tr, interpolation, ICU and RTL. A custom loader owns resource failures and retries.
Gallery walkthrough · browser route /#/localization.
These examples use the current checkout; published 1.x APIs can differ.
Load interpolation through an injected catalog
import 'package:activity/activity.dart';
import 'package:flutter/widgets.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final delegate = ActiveLocalizationDelegate(
supportedLocales: [const Locale('en')],
loader: (_) async => {'hello': 'Hello {name}'},
);
final messages = await delegate.load(const Locale('en'));
assert(
messages.translate('hello', parameters: {'name': 'Ada'}) == 'Hello Ada',
);
}
Use fallback messages
import 'package:activity/activity.dart';
import 'package:flutter/widgets.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final delegate = ActiveLocalizationDelegate(
supportedLocales: [const Locale('en'), const Locale('sw')],
fallbackLocale: const Locale('en'),
loader:
(locale) async => locale.languageCode == 'en' ? {'save': 'Save'} : {},
);
final messages = await delegate.load(const Locale('sw'));
assert(messages.translate('save') == 'Save');
assert(
messages.translate('missing', fallback: 'Unavailable') == 'Unavailable',
);
}
- Inheritance
-
- Object
- LocalizationsDelegate<
ActiveLocalization> - ActiveLocalizationDelegate
Constructors
-
ActiveLocalizationDelegate({required Iterable<
Locale> supportedLocales, Locale? fallbackLocale, TranslationLoader? loader, AssetBundle? bundle, String assetPath = 'assets/language'})
Properties
- assetPath → String
-
final
- bundle → AssetBundle?
-
final
- fallbackLocale → Locale?
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- loader → TranslationLoader?
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
supportedLocales
→ List<
Locale> -
final
- type → Type
-
The type of the object returned by the load method, T by default.
no setterinherited
Methods
-
isSupported(
Locale locale) → bool -
Whether resources for the given locale can be loaded by this delegate.
override
-
load(
Locale locale) → Future< ActiveLocalization> -
Start loading the resources for
locale. The returned future completes when the resources have finished loading.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
shouldReload(
covariant ActiveLocalizationDelegate old) → bool -
Returns true if the resources for this delegate should be loaded
again by calling the load method.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited