Alerts¶
The Alert class provides imperative access to
the host platform's alert dialogs and action sheets. Alerts are not
part of the element tree — they're fire-and-forget calls that present
a native dialog and dispatch button callbacks.
Imperative system alerts.
Modeled on React Native's Alert.alert(). Alerts are not part of
the element tree — they're imperative, fire-and-forget calls that
trigger a native dialog.
Example
Classes:
| Name | Description |
|---|---|
Alert |
Imperative alert / action-sheet helper. |
Alert
¶
Imperative alert / action-sheet helper.
All methods are static. Use Alert.show() for an alert dialog
and pass style="action_sheet" for an iOS-style action sheet.
Methods:
| Name | Description |
|---|---|
show |
Present a native alert dialog or action sheet. |
confirm |
Convenience wrapper for two-button confirm/cancel dialogs. |
show
staticmethod
¶
show(*, title: str, message: Optional[str] = None, buttons: Optional[List[Dict[str, Any]]] = None, style: str = 'alert') -> None
Present a native alert dialog or action sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Dialog title (required). |
required |
message
|
Optional[str]
|
Optional body text. |
None
|
buttons
|
Optional[List[Dict[str, Any]]]
|
Each button is |
None
|
style
|
str
|
|
'alert'
|
On iOS this uses UIAlertController; on Android it uses
AlertDialog.Builder. On the test backend the call is a
no-op so unit tests don't need to mock UIKit/AndroidX.
Patterns¶
- Confirm before destructive actions: pair a
"destructive"button with a"cancel"button viaAlert.confirm. - Action sheets: pass
style="action_sheet"to render an iOS-style bottom sheet; on Android this falls back to a regular dialog. - Pickers: the built-in
Pickercomponent is implemented on top of action sheets — use it for select/dropdown widgets.
Testing¶
When running off-device (e.g., in unit tests), Alert.show records
each call to Alert._test_log instead of presenting a dialog. Reset
the log with Alert._test_log.clear() between cases.