addGallery method
Adds a media gallery to the message.
Galleries display multiple images in a grid layout, providing a more compact and visually appealing way to show multiple media items. This method directly accepts a list of MediaItem instances.
Discord supports up to 10 items per gallery. The gallery must contain at least one item.
Example:
// Create gallery from local files
builder.addGallery([
MediaItem.fromFile(File('assets/image1.png'), 'image1.png'),
MediaItem.fromFile(File('assets/image2.png'), 'image2.png'),
MediaItem.fromFile(File('assets/image3.png'), 'image3.png'),
]);
// Mix local and network sources with metadata
builder.addGallery([
MediaItem.fromFile(
File('assets/local.png'),
'local.png',
description: 'Local image',
),
MediaItem.fromNetwork(
'https://example.com/remote.jpg',
description: 'Remote image',
spoiler: true,
),
]);
Throws:
- ArgumentError if the list is empty
- ArgumentError if the list contains more than 10 items
See also:
- addFile for single file attachments
- MediaItem.fromFile for creating media items from local files
- MediaItem.fromNetwork for creating media items from URLs
Implementation
void addGallery(List<MediaItem> items) {
_components.add(MediaGallery(items: items));
}