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:pizzaplanner/main.dart';
|
||||||
|
|
||||||
import 'package:timezone/timezone.dart' as tz;
|
import 'package:timezone/timezone.dart' as tz;
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
part 'PizzaEvent.g.dart';
|
part 'PizzaEvent.g.dart';
|
||||||
|
|
||||||
|
@ -49,9 +50,12 @@ class PizzaEvent extends HiveObject{
|
||||||
.fold(0, (a, b) => a+b));
|
.fold(0, (a, b) => a+b));
|
||||||
stepTime = stepTime.subtract(durationToFirstStep);
|
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) {
|
for (var recipeStep in this.recipe.recipeSteps) {
|
||||||
await flutterLocalNotificationsPlugin.zonedSchedule(
|
await flutterLocalNotificationsPlugin.zonedSchedule(
|
||||||
"${name}_${recipeStep.name}_${dateTime.millisecondsSinceEpoch}".hashCode,
|
notificationId,
|
||||||
recipeStep.name,
|
recipeStep.name,
|
||||||
null,
|
null,
|
||||||
stepTime,
|
stepTime,
|
||||||
|
@ -60,7 +64,9 @@ class PizzaEvent extends HiveObject{
|
||||||
uiLocalNotificationDateInterpretation:
|
uiLocalNotificationDateInterpretation:
|
||||||
UILocalNotificationDateInterpretation.absoluteTime
|
UILocalNotificationDateInterpretation.absoluteTime
|
||||||
);
|
);
|
||||||
|
recipeStep.notificationId = notificationId;
|
||||||
stepTime = stepTime.add(Duration(seconds: recipeStep.getCurrentWaitInSeconds()));
|
stepTime = stepTime.add(Duration(seconds: recipeStep.getCurrentWaitInSeconds()));
|
||||||
|
notificationId++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,9 +34,11 @@ class RecipeStep extends HiveObject {
|
||||||
|
|
||||||
@HiveField(8)
|
@HiveField(8)
|
||||||
DateTime? completedOn;
|
DateTime? completedOn;
|
||||||
|
|
||||||
bool get completed => _completed();
|
bool get completed => _completed();
|
||||||
|
|
||||||
|
@HiveField(9)
|
||||||
|
int notificationId = -1;
|
||||||
|
|
||||||
RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps) {
|
RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps) {
|
||||||
waitValue = waitMin;
|
waitValue = waitMin;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:fluttericon/font_awesome5_icons.dart';
|
||||||
|
|
||||||
import 'package:pizzaplanner/entities/PizzaEvent.dart';
|
import 'package:pizzaplanner/entities/PizzaEvent.dart';
|
||||||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||||
|
import 'package:pizzaplanner/main.dart';
|
||||||
import 'package:pizzaplanner/util.dart';
|
import 'package:pizzaplanner/util.dart';
|
||||||
|
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
@ -151,6 +152,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
child: Text("Review", style: TextStyle(color: Colors.white)),
|
child: Text("Review", style: TextStyle(color: Colors.white)),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
|
||||||
if (this.name.length == 0){
|
if (this.name.length == 0){
|
||||||
setState(() { this.nameValidation = true; });
|
setState(() { this.nameValidation = true; });
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue