From cbbd83fa46d5ce39212862c218fc1d99621798f8 Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Mon, 30 Aug 2021 21:27:54 +0200 Subject: [PATCH] added longpress to snooze button that allows the user to select the datetime when to snooze to --- lib/pages/PizzaEventNotificationPage.dart | 71 ++++++++++++++--------- todo.md | 4 +- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/lib/pages/PizzaEventNotificationPage.dart b/lib/pages/PizzaEventNotificationPage.dart index 11f15f1..c97f298 100644 --- a/lib/pages/PizzaEventNotificationPage.dart +++ b/lib/pages/PizzaEventNotificationPage.dart @@ -1,5 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:hive/hive.dart'; import 'package:pizzaplanner/entities/PizzaEvent.dart'; @@ -89,34 +90,25 @@ 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); - - var newTime = DateTime.now().add(const Duration(minutes: 15)); - - await flutterLocalNotificationsPlugin.zonedSchedule( - recipeStep.notificationId, - recipeStep.name, - null, - tz.TZDateTime.from(newTime, tz.local), - platformChannelSpecific, - androidAllowWhileIdle: true, - payload: this.widget.payload, - uiLocalNotificationDateInterpretation: - UILocalNotificationDateInterpretation.absoluteTime - ); - recipeStep.dateTime = newTime; - pizzaEvent.save(); + setRecipeStepNotificatcion(DateTime.now().add(const Duration(minutes: 15))); Navigator.pop(context); }, + onLongPress: () async { + var future5Min = DateTime.now().add(Duration(minutes: 5)); + DatePicker.showDateTimePicker(context, + showTitleActions: true, + minTime: future5Min, + currentTime: future5Min, + maxTime: DateTime.now().add(Duration(days: 365*10)), + onConfirm: (newEventTime) { + setState((){ + setRecipeStepNotificatcion(newEventTime); + Navigator.pop(context); + }); + } + ); + + }, ) ) ), @@ -173,5 +165,32 @@ class PizzaEventNotificationState extends State { ] ); } + + void setRecipeStepNotificatcion(DateTime newTime) 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(newTime, tz.local), + platformChannelSpecific, + androidAllowWhileIdle: true, + payload: this.widget.payload, + uiLocalNotificationDateInterpretation: + UILocalNotificationDateInterpretation.absoluteTime + ); + recipeStep.dateTime = newTime; + pizzaEvent.save(); + } } diff --git a/todo.md b/todo.md index d0424a2..1157dd7 100644 --- a/todo.md +++ b/todo.md @@ -7,6 +7,4 @@ - add decimals to ingredients table when below a certain % or <5g whatever -- move ingredients table when adding a pizza event from confirm date dialog to main add pizza page - -- add another button (or longpress) on snooze button with a datetime picker \ No newline at end of file +- move ingredients table when adding a pizza event from confirm date dialog to main add pizza page \ No newline at end of file