notification_service.dart 889 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import 'package:flutter/foundation.dart';
  2. import 'package:local_notifier/local_notifier.dart';
  3. const _appName = "AppFlowy";
  4. /// Manages Local Notifications
  5. ///
  6. /// Currently supports:
  7. /// - MacOS
  8. /// - Windows
  9. /// - Linux
  10. ///
  11. class NotificationService {
  12. static Future<void> initialize() async {
  13. await localNotifier.setup(
  14. appName: _appName,
  15. shortcutPolicy: ShortcutPolicy.requireCreate, // Windows Specific
  16. );
  17. }
  18. }
  19. /// Creates and shows a Notification
  20. ///
  21. class NotificationMessage {
  22. NotificationMessage({
  23. required String title,
  24. required String body,
  25. String? identifier,
  26. VoidCallback? onClick,
  27. }) {
  28. _notification = LocalNotification(
  29. identifier: identifier,
  30. title: title,
  31. body: body,
  32. )..onClick = onClick;
  33. _show();
  34. }
  35. late final LocalNotification _notification;
  36. void _show() => _notification.show();
  37. }