getMessage method

  1. @override
String getMessage(
  1. String code, {
  2. List<Object>? args,
  3. Locale? locale,
  4. String? defaultMessage,
})
override

Retrieve a message for the given code.

Parameters:

  • code: The message code to look up
  • args: Optional arguments for placeholder substitution
  • locale: Optional locale for message resolution

Returns the resolved message string, or the code itself if not found.

Example:

// Simple message
final msg1 = getMessage('hello'); // "Hello"

// Message with parameters
final msg2 = getMessage('welcome', args: ['Alice']); // "Welcome Alice!"

// Message for specific locale
final msg3 = getMessage('hello', locale: Locale('es')); // "Hola"

Implementation

@override
String getMessage(String code, {List<Object>? args, Locale? locale, String? defaultMessage}) {
  if(_messageSource == null) {
    throw InvalidArgumentException("Message source has not been initialized yet");
  }

  return _messageSource!.getMessage(code, args: args, locale: locale, defaultMessage: defaultMessage);
}