InlineKeyboard class
Represents an inline keyboard that appears right next to the message it belongs to. This is a shortcut for InlineKeyboardMarkup.
With InlineKeyboard
you can create a keyboard with buttons that can be pressed inline. This is useful for things like inline menus.
For example, you can create a button that will open a URL when pressed or a button that will send a callback query to your bot.
// Create a new inline keyboard.
var keyboard = InlineKeyboard();
// Add a button with the text "Open Google" and the URL "https://google.com".
keyboard.addUrl("Open Google", "https://google.com");
// Add a button with the text "Send a callback query" and the data "callback_query".
keyboard.add("Send a callback query", "callback_query");
// Send the keyboard with the message "Hello World!".
ctx.api.sendMessage(ctx.id, "Hello World!", replyMarkup: keyboard);
You can also add multiple rows to the keyboard. This is useful if you want to create a menu with multiple pages. Simply use the InlineKeyboard.row method to add a new row.
// Create a new inline keyboard.
var keyboard = InlineKeyboard();
// Add a button with the text "Open Google" and the URL "https://google.com".
keyboard.addUrl("Open Google", "https://google.com");
// Add a new row.
keyboard.row();
// Add a button with the text "Send a callback query" and the data "callback_query".
keyboard.add("Send a callback query", "callback_query");
// Send the keyboard with the message "Hello World!".
ctx.api.sendMessage(ctx.id, "Hello World!", replyMarkup: keyboard);
Additionally, you can also add - web apps by using the InlineKeyboard.addWebApp method,
- Inheritance
-
- Object
- ReplyMarkup
- InlineKeyboardMarkup
- InlineKeyboard
Constructors
- InlineKeyboard()
- Creates a new InlineKeyboard.
Properties
- 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
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
String text, String data) → InlineKeyboard -
Adds a Inline Keyboard Button with given
text
anddata
to the current row. -
addLogin(
String text, String url, {String? forwardText, String? botUsername, bool? requestWriteAccess}) → InlineKeyboard -
Adds a button withgiven
text
and login url (url
) -
addUrl(
String text, String url) → InlineKeyboard -
Adds a button with given
text
andurl
. When tapped the given URL is opened. -
addWebApp(
String text, String url) → InlineKeyboard - Adds a button with a URL to your web app that will be launched when the button is pressed.
-
game(
String text, {CallbackGame game = const CallbackGame()}) → InlineKeyboard - Adds a callback game button to the keyboard
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pay(
String text, {bool pay = true}) → InlineKeyboard - Adds a Pay Button to the keyboard
-
row(
) → InlineKeyboard - Adds a new row to the current keyboard.
-
switchInlineQuery(
String text, [String query = ""]) → InlineKeyboard -
Adds a button with the given
text
label when tapped prompts user to prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inlinequery
in the input field -
switchInlineQueryChosenChat(
String text, {String query = "", bool? allowUserChats, bool? allowBotChats, bool? allowGroupChats, bool? allowChannelChats}) → InlineKeyboard -
Adds a button with the given
text
label when tapped the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field. -
switchInlineQueryCurrentChat(
String text, [String query = ""]) → InlineKeyboard -
Adds a button with the given
text
label when tapped the button will insert the bot's username and the specified inlinequery
in the current chat's input field. -
toJson(
) → Map< String, dynamic> -
Converts an InlineKeyboardMarkup object to JSON object
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited