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
|
||||
);
|
||||
recipeStep.notificationId = notificationId;
|
||||
recipeStep.dateTime = stepTime;
|
||||
stepTime = stepTime.add(Duration(seconds: recipeStep.getCurrentWaitInSeconds()));
|
||||
stepId++;
|
||||
}
|
||||
|
|
|
@ -32,29 +32,32 @@ class RecipeStep extends HiveObject {
|
|||
@HiveField(7)
|
||||
List<RecipeSubStep> subSteps;
|
||||
|
||||
@HiveField(8)
|
||||
DateTime? completedOn;
|
||||
bool get completed => _completed();
|
||||
|
||||
@HiveField(8)
|
||||
late DateTime dateTime;
|
||||
|
||||
@HiveField(9)
|
||||
late bool _completed;
|
||||
|
||||
bool get completed => _checkCompleted();
|
||||
|
||||
@HiveField(10)
|
||||
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;
|
||||
this.dateTime = dateTime ?? DateTime.now();
|
||||
this._completed = completed;
|
||||
}
|
||||
|
||||
bool _completed(){
|
||||
bool _checkCompleted(){
|
||||
return subSteps.length > 0 ?
|
||||
subSteps.every((subStep) => subStep.completed) :
|
||||
completedOn != null;
|
||||
this._completed;
|
||||
}
|
||||
|
||||
void completeStepNow(){
|
||||
if (subSteps.isNotEmpty){
|
||||
subSteps.forEach((subStep) { subStep.completeNow(); });
|
||||
} else {
|
||||
completedOn = DateTime.now();
|
||||
}
|
||||
|
||||
void completeStepNow() {
|
||||
this.subSteps.forEach((subStep) { subStep.completeNow();});
|
||||
this._completed = true;
|
||||
}
|
||||
|
||||
int convertToSeconds(int value){
|
||||
|
|
|
@ -24,13 +24,17 @@ class RecipeStepAdapter extends TypeAdapter<RecipeStep> {
|
|||
fields[3] as int,
|
||||
fields[4] as int,
|
||||
(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
|
||||
void write(BinaryWriter writer, RecipeStep obj) {
|
||||
writer
|
||||
..writeByte(8)
|
||||
..writeByte(11)
|
||||
..writeByte(0)
|
||||
..write(obj.name)
|
||||
..writeByte(1)
|
||||
|
@ -46,7 +50,13 @@ class RecipeStepAdapter extends TypeAdapter<RecipeStep> {
|
|||
..writeByte(6)
|
||||
..write(obj.description)
|
||||
..writeByte(7)
|
||||
..write(obj.subSteps);
|
||||
..write(obj.subSteps)
|
||||
..writeByte(8)
|
||||
..write(obj.dateTime)
|
||||
..writeByte(9)
|
||||
..write(obj._completed)
|
||||
..writeByte(10)
|
||||
..write(obj.notificationId);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -99,18 +99,22 @@ class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
|
|||
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(DateTime.now().add(const Duration(minutes: 15)), tz.local),
|
||||
tz.TZDateTime.from(newTime, tz.local),
|
||||
platformChannelSpecific,
|
||||
androidAllowWhileIdle: true,
|
||||
payload: this.widget.payload,
|
||||
uiLocalNotificationDateInterpretation:
|
||||
UILocalNotificationDateInterpretation.absoluteTime
|
||||
);
|
||||
recipeStep.dateTime = newTime;
|
||||
pizzaEvent.save();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue