A message described by codes rather than text: the codes to look up, the arguments to fill in and a default text.
It lets code that produces a message (a validator, a service throwing a
business error) leave the wording and the translation to the
MessageSource. Several codes go from specific to general, so that a
translation can target one form field or all of them. Validation errors
implement it; most applications only pass such objects to
MessageSource.getMessageFromResolvable, or use
DefaultMessageSourceResolvable.
// "required.user.email" if translated, else "required", else the
// default text.
class FieldError implements MessageSourceResolvable {
FieldError(this.field);
final String field;
@override
List<String> get codes => ['required.user.$field', 'required'];
@override
List<Object?> get arguments => [field];
@override
String? get defaultMessage => '$field is required';
}
messageSource.getMessageFromResolvable(FieldError('email'));
Spring (Java):
class FieldError implements MessageSourceResolvable {
public String[] getCodes() { ... }
public Object[] getArguments() { ... }
public String getDefaultMessage() { ... }
}
Properties
-
arguments
→ List<
Object?> -
The values for the
{0},{1}, ... placeholders; an argument that is itself a MessageSourceResolvable is translated first.no setter -
codes
→ List<
String> -
The codes tried in order; the last is the most general.
no setter
- defaultMessage → String?
-
The text used when no code is found;
nullmakes a missing message an error.no setter - 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.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited