DefaultMessageSourceResolvable class final
A ready-made MessageSourceResolvable: codes, arguments and a default message given as values.
Use it to pass a message by code to code that translates it later, for example an error a service returns and the UI shows in the user's language, or a translated label as an argument of another message.
// The German error text, or "Invalid e-mail" when none is defined.
final message = context.getMessageFromResolvable(
const DefaultMessageSourceResolvable(
['error.user.email', 'error.email'],
arguments: ['ada@'],
defaultMessage: 'Invalid e-mail',
),
locale: 'de',
);
// Resolvables can be arguments of other messages:
context.getMessage(
'field.required',
args: [DefaultMessageSourceResolvable.code('label.email')],
);
Spring (Java):
String message = context.getMessage(
new DefaultMessageSourceResolvable(
new String[] {"error.user.email", "error.email"},
new Object[] {"ada@"}, "Invalid e-mail"),
Locale.GERMAN);
- Implemented types
Constructors
-
DefaultMessageSourceResolvable(List<
String> codes, {List<Object?> arguments = const [], String? defaultMessage}) -
Creates a resolvable that tries
codesin order, fills inargumentsand falls back todefaultMessage.const -
DefaultMessageSourceResolvable.code(String code, {List<
Object?> arguments = const [], String? defaultMessage}) -
Creates a resolvable with a single
code.
Properties
-
arguments
→ List<
Object?> -
The values for the
{0},{1}, ... placeholders; an argument that is itself a MessageSourceResolvable is translated first.final -
codes
→ List<
String> -
The codes tried in order; the last is the most general.
final
- defaultMessage → String?
-
The text used when no code is found;
nullmakes a missing message an error.final - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited