Notifica immediata:
import 'package:bicorush/services/notification/notification_service.dart';
Center(
child: ElevatedButton(
onPressed: () {
NotificationService().showNotification(
title: "BicoRush",
body: "Notifica immediata",
);
},
child: const Text("Send Notification NOW"),
),
),
Notifica schedulata:
import 'package:bicorush/services/notification/notification_service.dart';
import 'package:timezone/timezone.dart' as tz;
import 'package:timezone/data/latest_all.dart' as tz;
@override
void initState() {
//...
tz.initializeTimeZones();
}
import 'package:bicorush/services/notification/notification_service.dart';
import 'package:timezone/timezone.dart' as tz;
import 'package:timezone/data/latest_all.dart' as tz;
Center(
child: ElevatedButton(
onPressed: () {
NotificationService().scheduleNotification(
title: "BicoRush",
body: "Notifica in 5 secondi",
scheduledDate: tz.TZDateTime.now(
tz.local,
).add(const Duration(seconds: 5)),
);
},
child: const Text("Send Notification"),
),
),
main.dart:
import 'package:bicorush/services/notification/notification_service.dart';
void main() async {
//...
NotificationService().initNotification();
//...
}
tmep
widget.notificationService.scheduleNotification(
title: "Just a reminder...",
body:
"You have a task due tomorrow: ${task.title}!",
scheduledDate: tz.TZDateTime.from(
task.dueDate!,
tz.local,
).subtract(Duration(days: 1)),
),