resolve method

  1. @override
String resolve(
  1. PlaceholderPartResolutionContext resolutionContext
)
override

Represents a segment or fragment of a placeholder expression.

A Part is a building block used during placeholder parsing and resolution. It may represent literal text or a placeholder that must be resolved using a `PartResolutionContext`.

This interface is used by the placeholder parsing engine to build a list of Parts which can then be resolved dynamically during runtime.

You typically do not implement this directly unless building a custom placeholder parser or resolver engine.

Example usage

final context = MyPartResolutionContext(); // Your custom implementation
final parts = <Part>[...]; // Populated from parsing
final resolved = Part.resolveAll(parts, context);
print(resolved); // Prints the fully resolved placeholder string

Resolves this part using the given resolutionContext.

The implementation will determine how to transform this part into a final string result. For example, a placeholder part would extract its value from the context, while a literal part would return itself.

Example

part.resolve(context); // -> "resolved value"

Implementation

@override
String resolve(PlaceholderPartResolutionContext resolutionContext) {
  String? value = _resolveRecursively(resolutionContext);
  if (value != null) {
    return value;
  } else if (fallback != null) {
    return fallback!;
  }
  return resolutionContext.handleUnresolvablePlaceholder(key, text());
}