added incremental notification ids stored in the recipeStep for cancelling
This commit is contained in:
parent
3f5b537ef0
commit
41b003acb7
3 changed files with 12 additions and 2 deletions
|
@ -5,6 +5,7 @@ import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
|||
import 'package:pizzaplanner/main.dart';
|
||||
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
import 'dart:math';
|
||||
|
||||
part 'PizzaEvent.g.dart';
|
||||
|
||||
|
@ -49,9 +50,12 @@ class PizzaEvent extends HiveObject{
|
|||
.fold(0, (a, b) => a+b));
|
||||
stepTime = stepTime.subtract(durationToFirstStep);
|
||||
|
||||
final List<PendingNotificationRequest> pendingNotificationRequests = await flutterLocalNotificationsPlugin.pendingNotificationRequests();
|
||||
int notificationId = pendingNotificationRequests.map((pendingNotification) => pendingNotification.id).fold(0, max);
|
||||
|
||||
for (var recipeStep in this.recipe.recipeSteps) {
|
||||
await flutterLocalNotificationsPlugin.zonedSchedule(
|
||||
"${name}_${recipeStep.name}_${dateTime.millisecondsSinceEpoch}".hashCode,
|
||||
notificationId,
|
||||
recipeStep.name,
|
||||
null,
|
||||
stepTime,
|
||||
|
@ -60,7 +64,9 @@ class PizzaEvent extends HiveObject{
|
|||
uiLocalNotificationDateInterpretation:
|
||||
UILocalNotificationDateInterpretation.absoluteTime
|
||||
);
|
||||
recipeStep.notificationId = notificationId;
|
||||
stepTime = stepTime.add(Duration(seconds: recipeStep.getCurrentWaitInSeconds()));
|
||||
notificationId++;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,9 +34,11 @@ class RecipeStep extends HiveObject {
|
|||
|
||||
@HiveField(8)
|
||||
DateTime? completedOn;
|
||||
|
||||
bool get completed => _completed();
|
||||
|
||||
@HiveField(9)
|
||||
int notificationId = -1;
|
||||
|
||||
RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps) {
|
||||
waitValue = waitMin;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:fluttericon/font_awesome5_icons.dart';
|
|||
|
||||
import 'package:pizzaplanner/entities/PizzaEvent.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||
import 'package:pizzaplanner/main.dart';
|
||||
import 'package:pizzaplanner/util.dart';
|
||||
|
||||
import 'package:hive/hive.dart';
|
||||
|
@ -151,6 +152,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
|||
child: TextButton(
|
||||
child: Text("Review", style: TextStyle(color: Colors.white)),
|
||||
onPressed: () async {
|
||||
|
||||
if (this.name.length == 0){
|
||||
setState(() { this.nameValidation = true; });
|
||||
return;
|
||||
|
|
Loading…
Add table
Reference in a new issue