Skip to content

Commit

Permalink
chore(windows_ui): add example of sending a toast notification (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
halildurmus committed Jun 1, 2023
1 parent 73f2b3a commit 4668bcb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/windows_ui/example/README.md
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
32 changes: 32 additions & 0 deletions packages/windows_ui/example/notification.dart
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);
}
}
}

0 comments on commit 4668bcb

Please sign in to comment.