From 757b43779db732d6b23195974d01d7c1c7c6c06a Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Thu, 19 Aug 2021 21:43:00 +0200 Subject: [PATCH] added code for 'sleep' button on notification page --- lib/pages/PizzaEventNotificationPage.dart | 28 ++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/pages/PizzaEventNotificationPage.dart b/lib/pages/PizzaEventNotificationPage.dart index 2ff3f51..2b1177d 100644 --- a/lib/pages/PizzaEventNotificationPage.dart +++ b/lib/pages/PizzaEventNotificationPage.dart @@ -1,8 +1,12 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:hive/hive.dart'; import 'package:pizzaplanner/entities/PizzaEvent.dart'; import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart'; +import 'package:pizzaplanner/main.dart'; + +import 'package:timezone/timezone.dart' as tz; class PizzaEventNotificationPage extends StatefulWidget { final String? payload; @@ -80,7 +84,29 @@ class PizzaEventNotificationState extends State { child: TextButton( child: Text("Snooze 15 minutes", style: TextStyle(color: Colors.white)), onPressed: () async { - + flutterLocalNotificationsPlugin.cancel(recipeStep.notificationId); + + const androidPlatformChannelSpecifics = AndroidNotificationDetails( + "PizzaEventChannel", "PizzaEventChannel", "PizzaPlanner notification channel", + importance: Importance.max, + priority: Priority.high, + ticker: "ticker", + fullScreenIntent: true, + ); + const platformChannelSpecific = NotificationDetails(android: androidPlatformChannelSpecifics); + + await flutterLocalNotificationsPlugin.zonedSchedule( + recipeStep.notificationId, + recipeStep.name, + null, + tz.TZDateTime.from(DateTime.now().add(const Duration(minutes: 15)), tz.local), + platformChannelSpecific, + androidAllowWhileIdle: true, + payload: this.widget.payload, + uiLocalNotificationDateInterpretation: + UILocalNotificationDateInterpretation.absoluteTime + ); + Navigator.pop(context); }, ) )