搜尋套件、儲存庫與 APP 分類

套件詳情v0.9.1

flutter_platform_alert

一個外掛程式可協助呼叫原生 API 來播放警示音並顯示警示對話方塊。例如,它在 Windows 上橋接了 MessageBox 和 TaskDialogIndirect。

AndroidiOSmacOSWindowsLinux
近 30 天下載
1.2萬
喜歡數
145
Pub 分數
160

安裝套件

flutter pub add flutter_platform_alert

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 插件,可呼叫原生系統 API 來播放警示音並顯示平台特定的警告對話方塊。它在 Windows 上橋接 MessageBox 和 TaskDialogIndirect 等原生對話方塊機制,確保跨平台的一致使用者體驗。該套件支援 Android、iOS、macOS、Windows 和 Linux,非常適合需要系統層級通知或具有原生外觀與行為的警告之應用程式。

適用情境

  • 顯示系統原生警告對話方塊
  • 播放平台特定的提醒聲音
  • 與 Windows TaskDialogIndirect 集成
  • 確保警報在跨平台的一致性
  • 透過原生UI元素增強使用者回饋

主要特色

  • 跨平台原生對話框支援
  • 支援警示音效播放
  • Windows 特定的 TaskDialogIndirect 集成
  • 所需最小設定
  • 使用原生作業系統 API 以實現真實外觀與感覺

適合對象

  • 需要原生警告對話框的應用程式
  • 針對 Windows 的高級對話框開發人員
  • 需要系統級通知聲音的應用程式
  • 優先考慮平台一致性的使用者介面的專案
  • 建構桌面首選的 Flutter 應用程式的團隊

使用建議

  • 僅限特定平台(Android、iOS、macOS、Windows、Linux)
  • 需要目標系統的原生 API 存取權限
  • 可能根據作業系統設定表現不同
  • 不適用於網路平台
  • 取決於底層作業系統對話框的實作

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_platform_alert

2021 and onwards © Weizhong Yang a.k.a zonble.

Pub example workflow License: MIT Ask DeepWiki

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.

iOS Android macOS Windows Linux

It uses following API to show play alert sound.

It uses following API to show alert dialogs.

The package was developed and tested on

  • iOS 15
  • Android 11
  • macOS 11 Big Sur and mac OS 12 Monterey / Xcode 13
  • Windows 10 / Visual Studio Community 2019
  • Ubuntu 21.10

Getting Started

  • Add the dependency to your pubspec.yaml file by flutter pub add flutter_platform_alert.
  • Run flutter pub get.

To play platform alert sound.

import 'package:flutter_platform_alert/flutter_platform_alert.dart';
await FlutterPlatformAlert.playAlertSound();

To show a platform alert dialog.

import 'package:flutter_platform_alert/flutter_platform_alert.dart';
await FlutterPlatformAlert.playAlertSound();

final clickedButton = await FlutterPlatformAlert.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';
await FlutterPlatformAlert.playAlertSound();

final result = await FlutterPlatformAlert.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

Android

iOS 16 in Simulator

iOS

iOS 15 in Simulator (IosAlertOptions: alertStyle = IosAlertStyle.actionSheet)

iOS

macOS 12 Monterey

macOS

Windows 10 with MessageBox API

Windows

Windows 11 with TaskDialogIndirect API

Windows

Windows 11 with TaskDialogIndirect API that shows buttons as links

Windows

Ubuntu 21.10

linux

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案