Rain/lib/app/utils/notification.dart

44 lines
1.3 KiB
Dart
Raw Normal View History

2023-06-17 20:57:57 +03:00
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
2023-09-08 18:55:26 +03:00
import 'package:rain/app/controller/controller.dart';
2023-06-17 20:57:57 +03:00
import 'package:rain/main.dart';
import 'package:timezone/timezone.dart' as tz;
class NotificationShow {
Future showNotification(
int id,
String title,
String body,
DateTime date,
2023-09-07 16:49:26 +03:00
String icon,
2023-06-17 20:57:57 +03:00
) async {
2023-09-08 18:55:26 +03:00
final imagePath = await WeatherController().getLocalImagePath(icon);
2023-06-17 20:57:57 +03:00
AndroidNotificationDetails androidNotificationDetails =
2023-09-07 16:49:26 +03:00
AndroidNotificationDetails(
2025-03-15 23:40:48 +03:00
'Rain',
'DARK NIGHT',
priority: Priority.high,
importance: Importance.max,
playSound: false,
enableVibration: false,
largeIcon: FilePathAndroidBitmap(imagePath),
);
NotificationDetails notificationDetails = NotificationDetails(
android: androidNotificationDetails,
2023-06-17 20:57:57 +03:00
);
var scheduledTime = tz.TZDateTime.from(date, tz.local);
flutterLocalNotificationsPlugin.zonedSchedule(
id,
title,
body,
scheduledTime,
notificationDetails,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
2023-09-08 18:55:26 +03:00
payload: imagePath,
2023-06-17 20:57:57 +03:00
);
}
}