TKK_E32220213/code aplikasi/lib/services/notification_service.dart

45 lines
1.3 KiB
Dart

import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:flutter/material.dart';
class NotificationService {
static Future<void> initialize() async {
await AwesomeNotifications().initialize(
null, // icon untuk notifikasi
[
NotificationChannel(
channelKey: 'timer_channel',
channelName: 'Timer Notifications',
channelDescription: 'Notifikasi untuk timer pengering jagung',
defaultColor: Colors.blue,
ledColor: Colors.blue,
importance: NotificationImportance.High,
channelShowBadge: true,
enableVibration: true,
enableLights: true,
)
],
);
// Request permission
await AwesomeNotifications().isNotificationAllowed().then((isAllowed) async {
if (!isAllowed) {
await AwesomeNotifications().requestPermissionToSendNotifications();
}
});
}
static Future<void> showNotification({
required String title,
required String body,
}) async {
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: 0,
channelKey: 'timer_channel',
title: title,
body: body,
notificationLayout: NotificationLayout.Default,
),
);
}
}