Skip to content

Commit

Permalink
added notification feature for desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
Altafur Rahman authored and Altafur Rahman committed Aug 22, 2024
1 parent 28f39af commit fea3eed
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 28 deletions.
82 changes: 54 additions & 28 deletions lib/src/pages/sizzle/sizzle_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:blt/src/pages/sizzle/sizzle_state_provider.dart';
import 'package:blt/src/pages/sizzle/sizzle_timer.dart';
import 'dart:async';
import 'package:awesome_notifications/awesome_notifications.dart'; //Added for awesome notifications
import 'package:local_notifier/local_notifier.dart';

class SizzleHome extends ConsumerStatefulWidget {
const SizzleHome({Key? key}) : super(key: key);
Expand Down Expand Up @@ -47,39 +48,64 @@ class _SizzleHomeState extends ConsumerState<SizzleHome>
}

void _initializeNotifications() {
AwesomeNotifications().initialize(
null, //Notification icon
[
NotificationChannel(
if (Platform.isMacOS || Platform.isWindows || Platform.isLinux) {
_initializeDesktopNotifications();
} else {
AwesomeNotifications().initialize(
null, //Notification icon
[
NotificationChannel(
channelKey: 'sizzle_timer_channel',
channelName: 'Sizzle Timer Notifications',
channelDescription:
'Notifications for Sizzle Timer', //Added channel description
defaultColor: Color(0xFFFD5D00),
importance: NotificationImportance.High,
channelShowBadge: true,
)
],
channelGroups: [
NotificationChannelGroup(
channelGroupKey: 'sizzle_timer_group',
channelGroupName: 'sizzle Timer Group', //Added channel group name
)
],
debug: true,
);
}
}

Future<void> _showNotification() async {
if (Platform.isMacOS || Platform.isWindows || Platform.isLinux) {
await _showDesktopNotification();
} else {
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 14,
channelKey: 'sizzle_timer_channel',
channelName: 'Sizzle Timer Notifications',
channelDescription:
'Notifications for Sizzle Timer', //Added channel description
defaultColor: Color(0xFFFD5D00),
importance: NotificationImportance.High,
channelShowBadge: true,
)
],
channelGroups: [
NotificationChannelGroup(
channelGroupKey: 'sizzle_timer_group',
channelGroupName: 'sizzle Timer Group', //Added channel group name
)
],
debug: true,
title: 'Timer Stopped',
body: 'The timer has stopped. Are you still working?',
notificationLayout: NotificationLayout.Default,
),
);
}
}

void _initializeDesktopNotifications() async {
await localNotifier.setup(
appName: 'Sizzle Timer', // Set your app name
shortcutPolicy:
ShortcutPolicy.requireCreate, // Relevant mainly for Windows
);
}

Future<void> _showNotification() async {
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 14,
channelKey: 'sizzle_timer_channel',
title: 'Timer Stopped',
body: 'The timer has stopped. Are you still working?',
notificationLayout: NotificationLayout.Default,
),
Future<void> _showDesktopNotification() async {
LocalNotification notification = LocalNotification(
title: 'Timer Stopped',
body: 'The timer has stopped. Are you still working?',
);

await notification.show();
}

@override
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <awesome_notifications/awesome_notifications_plugin.h>
#include <file_selector_linux/file_selector_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <local_notifier/local_notifier_plugin.h>
#include <pasteboard/pasteboard_plugin.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
Expand All @@ -23,6 +24,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
g_autoptr(FlPluginRegistrar) local_notifier_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "LocalNotifierPlugin");
local_notifier_plugin_register_with_registrar(local_notifier_registrar);
g_autoptr(FlPluginRegistrar) pasteboard_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "PasteboardPlugin");
pasteboard_plugin_register_with_registrar(pasteboard_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
awesome_notifications
file_selector_linux
flutter_secure_storage_linux
local_notifier
pasteboard
sentry_flutter
url_launcher_linux
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Foundation
import awesome_notifications
import file_selector_macos
import flutter_secure_storage_macos
import local_notifier
import package_info_plus
import pasteboard
import path_provider_foundation
Expand All @@ -20,6 +21,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AwesomeNotificationsPlugin.register(with: registry.registrar(forPlugin: "AwesomeNotificationsPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
LocalNotifierPlugin.register(with: registry.registrar(forPlugin: "LocalNotifierPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PasteboardPlugin.register(with: registry.registrar(forPlugin: "PasteboardPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies:
webview_flutter: ^3.0.4
permission_handler: ^11.3.1
awesome_notifications: ^0.9.3+1
local_notifier: ^0.1.6

dev_dependencies:
flutter_launcher_icons: ">=0.9.0 <0.13.0"
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <awesome_notifications/awesome_notifications_plugin_c_api.h>
#include <file_selector_windows/file_selector_windows.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <local_notifier/local_notifier_plugin.h>
#include <pasteboard/pasteboard_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
Expand All @@ -21,6 +22,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FileSelectorWindows"));
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
LocalNotifierPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("LocalNotifierPlugin"));
PasteboardPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PasteboardPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
awesome_notifications
file_selector_windows
flutter_secure_storage_windows
local_notifier
pasteboard
permission_handler_windows
sentry_flutter
Expand Down

0 comments on commit fea3eed

Please sign in to comment.