lookupMessage method Null safety

String? lookupMessage(
  1. String? messageText,
  2. String? locale,
  3. String? name,
  4. List<Object>? args,
  5. String? meaning,
  6. {MessageIfAbsent? ifAbsent}
)

Return the localized version of a message. We are passed the original version of the message, which consists of a messageText that will be translated, and which may be interpolated based on one or more variables.

For example, if message="Hello, $name", then examples = {'name': 'Sparky'}. If not using the user's default locale, or if the locale is not easily detectable, explicitly pass locale.

Ultimately, the information about the enclosing function and its arguments will be extracted automatically but for the time being it must be passed explicitly in the name and args arguments.

Implementation

String? lookupMessage(String? messageText, String? locale, String? name,
    List<Object>? args, String? meaning,
    {MessageIfAbsent? ifAbsent}) {
  var actualName = computeMessageName(name, messageText, meaning);
  Object? translation;
  if (actualName != null) {
    translation = this[actualName];
  }
  if (translation == null) {
    return ifAbsent == null ? messageText : ifAbsent(messageText, args);
  } else {
    args = args ?? const [];
    return evaluateMessage(translation, args);
  }
}