Um plugin ajuda a chamar APIs nativas para tocar sons de alerta e exibir diálogos de alerta. Por exemplo, ele conecta MessageBox e TaskDialogIndirect no Windows.
Orientação gerada a partir de informações públicas. Apenas para referência.
Um plugin do Flutter que permite chamar APIs nativas do sistema para reproduzir sons de alerta e exibir diálogos de alerta específicos da plataforma. Ele conecta mecanismos nativos de diálogo, como MessageBox e TaskDialogIndirect no Windows, garantindo uma experiência consistente do usuário entre plataformas. O pacote suporta Android, iOS, macOS, Windows e Linux, tornando-o ideal para aplicativos que exigem notificações ou alertas de nível do sistema com aparência e comportamento nativos.
Casos de uso
Exibindo diálogos nativos do sistema
Reproduzindo sons de alerta específicos do plataforma
Integração com o Windows TaskDialogIndirect
Garantir a consistência entre plataformas em alertas
Melhorando o feedback do usuário com elementos de interface nativos
Principais recursos
Suporte nativo de diálogos multiplataforma
Suporta reprodução de som de alerta
Integração específica do Windows para TaskDialogIndirect
Configuração mínima necessária
Utiliza APIs nativas do sistema operacional para aparência e sensação autênticas
Indicado para
Aplicações que precisam de diálogos nativos de alerta
Desenvolvedores direcionando o Windows com diálogos avançados
Aplicativos que exigem sons de notificação em nível de sistema
Projetos com foco em interface do usuário consistente com a plataforma
Equipes desenvolvendo aplicativos Flutter com foco em desktop
Considerações
Limitado a plataformas específicas (Android, iOS, macOS, Windows, Linux)
Requer acesso à API nativa nos sistemas-alvo
Pode se comportar de forma diferente com base nas configurações do sistema operacional
Não adequado para plataformas da web
Depende das implementações de diálogos do sistema operacional subjacente
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
A simple plugin to present native alerts, including playing alert sounds and
showing alert dialogs on various platforms including iOS, Android, Windows,
macOS and Linux.
import'package:flutter_platform_alert/flutter_platform_alert.dart';
awaitFlutterPlatformAlert.playAlertSound();
final clickedButton = awaitFlutterPlatformAlert.showAlert(
windowTitle: 'This ia title',
text: 'This is body',
alertStyle: AlertButtonStyle.yesNoCancel,
iconStyle: IconStyle.information,
);
To show an alert dialog with custom button titles:
import'package:flutter_platform_alert/flutter_platform_alert.dart';
awaitFlutterPlatformAlert.playAlertSound();
final result = awaitFlutterPlatformAlert.showCustomAlert(
windowTitle: 'This is title',
text: 'This is body',
positiveButtonTitle: "Positive",
negativeButtonTitle: "Negative",
neutralButtonTitle: "Neutral",
options: PlatformAlertOptions(
windows: WindowsAlertOptions(
additionalWindowTitle: 'Window title',
showAsLinks: true,
),
),
);
Platform Alert Dialogs
Alert Styles
When calling showCustomAlert, you can assign any button titles and use up to
three buttons. Once there is no button title specified, it falls back to only an
"OK" button.
When calling showAlert, you can specify the buttons listed in the alert dialog
by passing alertStyle argument. The package follows the API design on Windows
(see the reference of MessageBox win32
API),
and it provides following styles:
Abort, retry and ignore
Cancel, try again and continue
OK
OK and cancel
Retry and cancel
Yes and no
Yes, no, and cancel
Since each platform has its own conventions, the order of these buttons are not
guaranteed to be the same.
Icon Styles
The package also follow the API design of MessageBox on Windows to add icons to
the alert dialogs (see the link above). There are several different icons styles
but actually four:
No icon
Warning icon
Information icon
Question icon
Please note that these icons are not available on iOS and Android.
Themes/Dark or Light Mode
On iOS and macOS, the alert dialogs follows the dark/light mode settings on
users' system. On Linux, the alert dialogs are rendered with current GTK theme.
On Windows, they are always in light mode even you choose to use dark mode on
Windows 10 and Windows 11.
On Android, the alert dialog uses the default theme of Material design
(as Theme.Material.Dialog.Alert).
Localization
Since the plugin calls native API, if you want to localize buttons like "OK",
"Cancel" and so on on Platforms like iOS, macOS and Linux, you have to do some
works in your app.
To localize the button titles on iOS and macOS, add "Localizable.strings" or
"Localizable.stringsdict" files in your Xcode project. Visit Apple's official
page for localization for further
information.
On Linux, we use gettext to localize
apps. Please update the PO files in your projects once you integrate the
plugin.
Android apps embeds resources for localized strings. The localized strings files
for the project are located under
android/src/main/res.
Once you need to add new languages, just fork the project and put your files
under the folder.
On Windows, the buttons on the message boxes will be in the Windows system
language.
License
The package in released under MIT License.
Screenshots
Android 13 on Pixel 6 emulator
iOS 16 in Simulator
iOS 15 in Simulator (IosAlertOptions: alertStyle = IosAlertStyle.actionSheet)
macOS 12 Monterey
Windows 10 with MessageBox API
Windows 11 with TaskDialogIndirect API
Windows 11 with TaskDialogIndirect API that shows buttons as links