-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(windows_ui): add example of sending a toast notification (#220)
- Loading branch information
1 parent
73f2b3a
commit 4668bcb
Showing
2 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
## Examples | ||
|
||
| Example | Description | | ||
| ------------- | ------------------------------------------------ | | ||
| [dialog.dart] | Demonstrates showing a MessageDialog to the user | | ||
| Example | Description | | ||
| ------------------- | ------------------------------------------------ | | ||
| [dialog.dart] | Demonstrates showing a MessageDialog to the user | | ||
| [notification.dart] | Demonstrates sending a toast notification | | ||
|
||
[dialog.dart]: https://github.com/dart-windows/dartwinrt/blob/main/packages/windows_ui/example/dialog.dart | ||
[notification.dart]: https://github.com/dart-windows/dartwinrt/blob/main/packages/windows_ui/example/notification.dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details. | ||
// All rights reserved. Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
import 'package:windows_ui/windows_ui.dart'; | ||
|
||
void main() async { | ||
const applicationId = 'dartwinrt'; | ||
// Create a toast notifier | ||
final toastNotifier = | ||
ToastNotificationManager.createToastNotifierWithId(applicationId); | ||
if (toastNotifier != null) { | ||
final toastContent = ToastNotificationManager.getTemplateContent( | ||
ToastTemplateType.toastText02); | ||
if (toastContent != null) { | ||
final xmlNodeList = toastContent.getElementsByTagName('text'); | ||
const title = 'Updates available'; | ||
const content = 'New updates have been found for this program.'; | ||
// Set the title on the toast notification | ||
xmlNodeList.item(0)?.appendChild(toastContent.createTextNode(title)); | ||
// Set the content on the toast notification | ||
xmlNodeList.item(1)?.appendChild(toastContent.createTextNode(content)); | ||
|
||
// Create a toast notification | ||
final toastNotification = | ||
ToastNotification.createToastNotification(toastContent); | ||
|
||
// Show the toast notification | ||
toastNotifier.show(toastNotification); | ||
} | ||
} | ||
} |