InlineKeyboard class abstract
Represents an inline keyboard that appears right next to the message it
belongs to. This is a utility wrapper around InlineKeyboardMarkup that
provides a fluent API for building inline keyboards.
With InlineKeyboard you can create keyboards with buttons that can be
pressed inline. This is useful for creating interactive menus, handling
callbacks, opening URLs, launching web apps, and more.
Basic Usage
// Create a simple inline keyboard
final keyboard = InlineKeyboard()
.text("Button 1", "callback_1")
.text("Button 2", "callback_2")
.row()
.url("Visit Website", "https://example.com");
// Send with message
await ctx.reply("Choose an option:", replyMarkup: keyboard);
Advanced Usage
// Create keyboard with various button types
final keyboard = InlineKeyboard()
.text("Callback", "data")
.url("Website", "https://example.com")
.row()
.webApp("Open App", "https://app.example.com")
.switchInline("Share", "query")
.row()
.login("Login", "https://auth.example.com")
.pay("Pay Now");
Building from Arrays
// From callback data pairs
final keyboard = InlineKeyboard.from([
[["Button 1", "data1"], ["Button 2", "data2"]],
[["Button 3", "data3"]]
]);
// From button objects
final buttons = [
[InlineKeyboard.buttonText("A", "a"), InlineKeyboard.buttonUrl("B", "https://b.com")],
[InlineKeyboard.buttonText("C", "c")]
];
final keyboard = InlineKeyboard.fromButtons(buttons);
- Implemented types
- Available extensions
- Annotations
-
- @freezed
Constructors
-
InlineKeyboard({@Default.new([<InlineKeyboardButton>[]]) @JsonKey.new(name: 'inline_keyboard') List<
List< inlineKeyboard})InlineKeyboardButton> > -
Creates a new InlineKeyboard instance.
constfactory
-
InlineKeyboard.column(List<
List< pairs)String> > -
Creates a single-column inline keyboard from label-data pairs.
factory
-
InlineKeyboard.from(List<
List< source)(String, String)> > -
Creates an inline keyboard from a 2D array of (text, callbackData) records.
factory
-
InlineKeyboard.fromButtons(List<
List< buttons)InlineKeyboardButton> > -
Creates an inline keyboard from a 2D array of InlineKeyboardButton objects.
factory
-
InlineKeyboard.fromJson(Map<
String, dynamic> json) -
Creates a new InlineKeyboard from JSON.
factory
-
InlineKeyboard.grid(List<
List< pairs, {required int columns})String> > -
Creates an inline keyboard with a grid layout.
factory
-
InlineKeyboard.singleRow(List<
List< pairs)String> > -
Creates a single-row inline keyboard from label-data pairs.
factory
Properties
- $type → String
-
Runtime type
no setter
-
Returns the total number of buttons in the keyboard.
no setter
-
copyWith
→ $InlineKeyboardCopyWith<
InlineKeyboard> -
Create a copy of InlineKeyboard
with the given fields replaced by the non-null parameter values.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
inlineKeyboard
→ List<
List< InlineKeyboardButton> > -
Array of button rows, each represented by an Array of InlineKeyboardButton objects
no setterinherited
- isEmpty → bool
-
Returns true if the keyboard has no buttons.
no setter
- isNotEmpty → bool
-
Returns true if the keyboard has buttons.
no setter
- rowCount → int
-
Returns the number of rows in the keyboard.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
InlineKeyboardButton button) → InlineKeyboard - Adds an InlineKeyboardButton to the current row.
-
addAll(
List< InlineKeyboardButton> buttons) → InlineKeyboard - Adds multiple buttons to the current row.
-
addRow(
List< InlineKeyboardButton> buttons) → InlineKeyboard - Adds a row of buttons to the keyboard.
-
copyText(
String text, {required String copyText, String? iconCustomEmojiId, StyleType? style}) → InlineKeyboard - Adds a copy text button to the current row.
-
game(
String text, {CallbackGame? game, String? iconCustomEmojiId, StyleType? style}) → InlineKeyboard - Adds a callback game button to the current row.
-
login(
String text, String url, {String? forwardText, String? botUsername, bool? requestWriteAccess, String? iconCustomEmojiId, StyleType? style}) → InlineKeyboard - Adds a login button to the current row.
-
map<
TResult extends Object?> (TResult $default(_InlineKeyboard value)) → TResult -
Available on InlineKeyboard, provided by the InlineKeyboardPatterns extension
Aswitch-like method, using callbacks. -
map<
TResult extends Object?> ({required TResult forceReply(ForceReply value), required TResult inlineKeyboard(InlineKeyboardMarkup value), required TResult keyboard(ReplyKeyboardMarkup value), required TResult keyboardRemove(ReplyKeyboardRemove value)}) → TResult -
Available on ReplyMarkup, provided by the ReplyMarkupPatterns extension
Aswitch-like method, using callbacks. -
mapOrNull<
TResult extends Object?> (TResult? $default(_InlineKeyboard value)?) → TResult? -
Available on InlineKeyboard, provided by the InlineKeyboardPatterns extension
A variant ofmapthat fallback to returningnull. -
mapOrNull<
TResult extends Object?> ({TResult? forceReply(ForceReply value)?, TResult? inlineKeyboard(InlineKeyboardMarkup value)?, TResult? keyboard(ReplyKeyboardMarkup value)?, TResult? keyboardRemove(ReplyKeyboardRemove value)?}) → TResult? -
Available on ReplyMarkup, provided by the ReplyMarkupPatterns extension
A variant ofmapthat fallback to returningnull. -
maybeMap<
TResult extends Object?> (TResult $default(_InlineKeyboard value)?, {required TResult orElse()}) → TResult -
Available on InlineKeyboard, provided by the InlineKeyboardPatterns extension
A variant ofmapthat fallback to returningorElse. -
maybeMap<
TResult extends Object?> ({TResult forceReply(ForceReply value)?, TResult inlineKeyboard(InlineKeyboardMarkup value)?, TResult keyboard(ReplyKeyboardMarkup value)?, TResult keyboardRemove(ReplyKeyboardRemove value)?, required TResult orElse()}) → TResult -
Available on ReplyMarkup, provided by the ReplyMarkupPatterns extension
A variant ofmapthat fallback to returningorElse. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pay(
String text, {bool pay = true, String? iconCustomEmojiId, StyleType? style}) → InlineKeyboard - Adds a pay button to the current row.
-
row(
) → InlineKeyboard - Adds a new row to the keyboard.
-
switchInline(
String text, {String query = "", String? iconCustomEmojiId, StyleType? style}) → InlineKeyboard - Adds an inline query button to the current row.
-
switchInlineChosen(
String text, {String query = "", bool? allowUserChats, bool? allowBotChats, bool? allowGroupChats, bool? allowChannelChats, String? iconCustomEmojiId, StyleType? style}) → InlineKeyboard - Adds an inline query button for chosen chat type to the current row.
-
switchInlineCurrentChat(
String text, {String query = "", String? iconCustomEmojiId, StyleType? style}) → InlineKeyboard - Adds an inline query button for current chat to the current row.
-
text(
String text, String data, {String? iconCustomEmojiId, StyleType? style}) → InlineKeyboard - Adds a callback query button to the current row.
-
toJson(
) → Map< String, dynamic> - Converts the InlineKeyboard to JSON.
-
toString(
) → String -
A string representation of this object.
override
-
transpose(
) → InlineKeyboard - Creates a new keyboard with the rows and columns transposed.
-
url(
String text, String url, {String? iconCustomEmojiId, StyleType? style}) → InlineKeyboard - Adds a URL button to the current row.
-
webApp(
String text, String url, {String? iconCustomEmojiId, StyleType? style}) → InlineKeyboard - Adds a web app button to the current row.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
- Creates a copy text button.
- Creates a callback game button.
- Creates a login button.
- Creates a pay button.
- Creates an inline query button.
- Creates an inline query button for chosen chat type.
- Creates an inline query button for the current chat.
- Creates a callback query button.
- Creates a URL button.
- Creates a web app button.