addFile method
Attaches a file to the message.
Files can be attached from local files or network URLs using various AttachedFile factory constructors. Each file attachment can include optional metadata such as spoiler flags, dimensions, and descriptions.
Example:
// From local file
builder.addFile(
AttachedFile.fromFile(
File('assets/document.pdf'),
'document.pdf',
description: 'Monthly report',
),
);
// From network URL
builder.addFile(
await AttachedFile.fromNetwork(
'https://example.com/image.png',
'image.png',
spoiler: true,
),
);
// From MediaItem
final mediaItem = MediaItem.fromFile(File('assets/logo.png'), 'logo.png');
builder.addFile(await AttachedFile.fromMediaItem(mediaItem));
See also:
- addGallery for displaying multiple images in a grid
- AttachedFile.fromFile for attaching local files
- AttachedFile.fromNetwork for downloading and attaching remote files
- AttachedFile.fromMediaItem for converting MediaItem instances
Implementation
void addFile(AttachedFile file) {
_components.add(file);
}