Alert
Display system alert or action sheet
Alert is used to display modal dialogs to users, supporting buttons, text fields and other interactive elements.
Use Alert to:
Note
Not available in Widget
Examples
let alert = new Alert();
alert.title = "Confirm";
alert.message = "Are you sure you want to proceed?";
alert.addAction("OK");
alert.addCancelAction("Cancel");
let index = await alert.present();let alert = new Alert();
alert.title = "Login";
alert.addTextField("Username");
alert.addSecureTextField("Password");
alert.addAction("Login");
await alert.present();
let username = alert.textFieldValue(0);
let password = alert.textFieldValue(1);Properties
title
- Type:
String
Alert title
The main title text displayed at the top of the alert.
alert.title = "Title"message
- Type:
String
Alert message
The detailed description text displayed below the title.
alert.message = "Description"Methods
addAction
Add a standard action button
Adds a button with default style.
addAction(title): voidtitle- The button text
Example:
alert.addAction("OK")addDestructiveAction
Add a destructive action button
Adds a red-colored button for destructive actions like delete.
addDestructiveAction(title): voidtitle- The button text
Example:
alert.addDestructiveAction("Delete")addCancelAction
Add a cancel button
Adds a cancel button. An alert can only have one cancel button; adding another will replace the previous one. The cancel button always returns index -1.
addCancelAction(title): voidtitle- The button text
Example:
alert.addCancelAction("Cancel")addTextField
Add a text field
Adds a plain text input field to the alert. Only available in alert style, not supported in sheet style.
addTextField(placeholder, text): Promiseplaceholder- Placeholder text for the fieldtext- Default text value
Returns: TextField object
Example:
alert.addTextField("Enter text", "Default")addSecureTextField
Add a secure text field
Adds a password input field where text is hidden. Only available in alert style.
addSecureTextField(placeholder, text): Promiseplaceholder- Placeholder text for the fieldtext- Default text value
Returns: TextField object
Example:
alert.addSecureTextField("Password")textFieldValue
Get text field value
Gets the current value of the text field at the specified index. Index starts from 0.
textFieldValue(index): stringindex- Text field index, starting from 0
Returns: The text value of the field
Example:
let value = alert.textFieldValue(0)present
Present the alert
Same as presentAlert(_:), displays as a modal dialog.
present(callback): voidcallback- Callback after user interaction
Returns: Promise that resolves to the tapped button index (-1 for cancel)
Example:
let index = await alert.present()presentAlert
Present as alert dialog
Displays a modal dialog in the center of the screen.
presentAlert(callback): voidcallback- Callback after user interaction
Returns: Promise that resolves to the tapped button index (-1 for cancel)
Example:
let index = await alert.presentAlert()presentSheet
Present as action sheet
Displays an action sheet from the bottom of the screen. Shows as popover on iPad. Note: Sheet style does not support text fields.
presentSheet(callback): voidcallback- Callback after user interaction
Returns: Promise that resolves to the tapped button index (-1 for cancel)
Example:
let index = await alert.presentSheet()