55 lines
1.7 KiB
Dart
55 lines
1.7 KiB
Dart
import 'package:awesome_notifications/awesome_notifications.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class NotificationService {
|
|
static const _channelKey = 'tabungankuy_channel';
|
|
|
|
/// Panggil di main.dart sebelum runApp()
|
|
static Future<void> initialize() async {
|
|
await AwesomeNotifications().initialize(
|
|
null, // null = pakai icon default app
|
|
[
|
|
NotificationChannel(
|
|
channelKey: _channelKey,
|
|
channelName: 'TabunganKuy',
|
|
channelDescription: 'Notifikasi pencapaian target tabungan',
|
|
defaultColor: const Color(0xFF5B9BD5),
|
|
ledColor: const Color(0xFF5B9BD5),
|
|
importance: NotificationImportance.High,
|
|
channelShowBadge: true,
|
|
playSound: true,
|
|
enableVibration: true,
|
|
),
|
|
],
|
|
debug: false,
|
|
);
|
|
}
|
|
|
|
/// Minta izin notifikasi — panggil di halaman pertama setelah login
|
|
static Future<void> requestPermission() async {
|
|
final isAllowed = await AwesomeNotifications().isNotificationAllowed();
|
|
if (!isAllowed) {
|
|
await AwesomeNotifications().requestPermissionToSendNotifications();
|
|
}
|
|
}
|
|
|
|
/// Notifikasi target tercapai
|
|
static Future<void> showTargetTercapai({
|
|
required String namaTarget,
|
|
required String nominal,
|
|
}) async {
|
|
await AwesomeNotifications().createNotification(
|
|
content: NotificationContent(
|
|
id: 1,
|
|
channelKey: _channelKey,
|
|
title: '🎉 Target Tercapai!',
|
|
body:
|
|
'Selamat! Tabungan "$namaTarget" kamu sudah mencapai target $nominal. Yuk buka celenganmu!',
|
|
notificationLayout: NotificationLayout.BigText,
|
|
category: NotificationCategory.Reminder,
|
|
wakeUpScreen: true,
|
|
autoDismissible: true,
|
|
),
|
|
);
|
|
}
|
|
} |