recipe step now stores the dateTime when the step is to be completed, and a bool if it's completed
This commit is contained in:
parent
21e922b036
commit
696b987957
4 changed files with 37 additions and 19 deletions
|
@ -68,6 +68,7 @@ class PizzaEvent extends HiveObject{
|
||||||
UILocalNotificationDateInterpretation.absoluteTime
|
UILocalNotificationDateInterpretation.absoluteTime
|
||||||
);
|
);
|
||||||
recipeStep.notificationId = notificationId;
|
recipeStep.notificationId = notificationId;
|
||||||
|
recipeStep.dateTime = stepTime;
|
||||||
stepTime = stepTime.add(Duration(seconds: recipeStep.getCurrentWaitInSeconds()));
|
stepTime = stepTime.add(Duration(seconds: recipeStep.getCurrentWaitInSeconds()));
|
||||||
stepId++;
|
stepId++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,28 +33,31 @@ class RecipeStep extends HiveObject {
|
||||||
List<RecipeSubStep> subSteps;
|
List<RecipeSubStep> subSteps;
|
||||||
|
|
||||||
@HiveField(8)
|
@HiveField(8)
|
||||||
DateTime? completedOn;
|
late DateTime dateTime;
|
||||||
bool get completed => _completed();
|
|
||||||
|
|
||||||
@HiveField(9)
|
@HiveField(9)
|
||||||
|
late bool _completed;
|
||||||
|
|
||||||
|
bool get completed => _checkCompleted();
|
||||||
|
|
||||||
|
@HiveField(10)
|
||||||
int notificationId = -1;
|
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, {DateTime? dateTime, bool completed=false}) {
|
||||||
waitValue = waitMin;
|
waitValue = waitMin;
|
||||||
|
this.dateTime = dateTime ?? DateTime.now();
|
||||||
|
this._completed = completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _completed(){
|
bool _checkCompleted(){
|
||||||
return subSteps.length > 0 ?
|
return subSteps.length > 0 ?
|
||||||
subSteps.every((subStep) => subStep.completed) :
|
subSteps.every((subStep) => subStep.completed) :
|
||||||
completedOn != null;
|
this._completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void completeStepNow(){
|
void completeStepNow() {
|
||||||
if (subSteps.isNotEmpty){
|
this.subSteps.forEach((subStep) { subStep.completeNow();});
|
||||||
subSteps.forEach((subStep) { subStep.completeNow(); });
|
this._completed = true;
|
||||||
} else {
|
|
||||||
completedOn = DateTime.now();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int convertToSeconds(int value){
|
int convertToSeconds(int value){
|
||||||
|
|
|
@ -24,13 +24,17 @@ class RecipeStepAdapter extends TypeAdapter<RecipeStep> {
|
||||||
fields[3] as int,
|
fields[3] as int,
|
||||||
fields[4] as int,
|
fields[4] as int,
|
||||||
(fields[7] as List).cast<RecipeSubStep>(),
|
(fields[7] as List).cast<RecipeSubStep>(),
|
||||||
)..waitValue = fields[5] as int?;
|
dateTime: fields[8] as DateTime?,
|
||||||
|
)
|
||||||
|
..waitValue = fields[5] as int?
|
||||||
|
.._completed = fields[9] as bool
|
||||||
|
..notificationId = fields[10] as int;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void write(BinaryWriter writer, RecipeStep obj) {
|
void write(BinaryWriter writer, RecipeStep obj) {
|
||||||
writer
|
writer
|
||||||
..writeByte(8)
|
..writeByte(11)
|
||||||
..writeByte(0)
|
..writeByte(0)
|
||||||
..write(obj.name)
|
..write(obj.name)
|
||||||
..writeByte(1)
|
..writeByte(1)
|
||||||
|
@ -46,7 +50,13 @@ class RecipeStepAdapter extends TypeAdapter<RecipeStep> {
|
||||||
..writeByte(6)
|
..writeByte(6)
|
||||||
..write(obj.description)
|
..write(obj.description)
|
||||||
..writeByte(7)
|
..writeByte(7)
|
||||||
..write(obj.subSteps);
|
..write(obj.subSteps)
|
||||||
|
..writeByte(8)
|
||||||
|
..write(obj.dateTime)
|
||||||
|
..writeByte(9)
|
||||||
|
..write(obj._completed)
|
||||||
|
..writeByte(10)
|
||||||
|
..write(obj.notificationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -100,17 +100,21 @@ class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
|
||||||
);
|
);
|
||||||
const platformChannelSpecific = NotificationDetails(android: androidPlatformChannelSpecifics);
|
const platformChannelSpecific = NotificationDetails(android: androidPlatformChannelSpecifics);
|
||||||
|
|
||||||
|
var newTime = DateTime.now().add(const Duration(minutes: 15));
|
||||||
|
|
||||||
await flutterLocalNotificationsPlugin.zonedSchedule(
|
await flutterLocalNotificationsPlugin.zonedSchedule(
|
||||||
recipeStep.notificationId,
|
recipeStep.notificationId,
|
||||||
recipeStep.name,
|
recipeStep.name,
|
||||||
null,
|
null,
|
||||||
tz.TZDateTime.from(DateTime.now().add(const Duration(minutes: 15)), tz.local),
|
tz.TZDateTime.from(newTime, tz.local),
|
||||||
platformChannelSpecific,
|
platformChannelSpecific,
|
||||||
androidAllowWhileIdle: true,
|
androidAllowWhileIdle: true,
|
||||||
payload: this.widget.payload,
|
payload: this.widget.payload,
|
||||||
uiLocalNotificationDateInterpretation:
|
uiLocalNotificationDateInterpretation:
|
||||||
UILocalNotificationDateInterpretation.absoluteTime
|
UILocalNotificationDateInterpretation.absoluteTime
|
||||||
);
|
);
|
||||||
|
recipeStep.dateTime = newTime;
|
||||||
|
pizzaEvent.save();
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue