showPopup method

  1. @override
void showPopup({
  1. String? title,
  2. required String message,
  3. List<PopupButton>? buttons,
  4. required void callback(
    1. String id
    ),
})
override

Bot API 6.2+ A method that shows a native popup described by the params argument of the type PopupParams. The Mini App will receive the event popupClosed when the popup is closed. If an optional callback parameter was passed, the callback function will be called and the field id of the pressed button will be passed as the first argument.

Implementation

@override
void showPopup({
  String? title,
  required String message,
  List<PopupButton>? buttons,
  required void Function(String id) callback,
}) {
  List<PopupButtonJSObject>? newButtons;
  if (buttons != null) {
    newButtons = [];
    for (var b in buttons) {
      newButtons.add(PopupButtonJSObject(id: b.id, type: b.type, text: b.text));
    }
  }

  Telegram.WebApp.showPopup(
    PopupParamsJSObject(title: title, message: message, buttons: newButtons?.toJS),
    callback.toJS,
  );
}