copyWith method

MessageBuilder copyWith(
  1. MessageBuilder builder
)

Creates a new builder combining this builder's components with another's.

The returned builder contains all components from this builder followed by all components from the provided builder. Neither original builder is modified.

Example:

final header = MessageBuilder.text('# Title');
final body = MessageBuilder.text('Content');

final combined = header.copyWith(body);
// combined has both title and content
// header and body remain unchanged

See also:

  • copy to create a simple copy without merging
  • appendFrom to modify this builder instead of creating a new one

Implementation

MessageBuilder copyWith(MessageBuilder builder) {
  return MessageBuilder()
    .._components.addAll(_components)
    .._components.addAll(builder._components);
}