Added timer id to Timer and TimerEntity

Signed-off-by: Andreas Fahrecker <AndreasFahrecker@gmail.com>
This commit is contained in:
Andreas Fahrecker
2020-10-13 15:03:46 +02:00
parent 88a9026966
commit e4c0a50ece
2 changed files with 27 additions and 11 deletions

View File

@@ -1,33 +1,45 @@
import 'package:meta/meta.dart';
import 'package:time_progress_calculator/persistence/timer_entity.dart';
import 'package:time_progress_calculator/uuid.dart';
@immutable
class Timer {
final String id;
final DateTime startTime;
final DateTime endTime;
Timer(this.startTime, this.endTime);
Timer(this.startTime, this.endTime, {String id})
: id = id ?? Uuid().generateV4();
Timer copyWith({DateTime startTime, DateTime endTime}) {
return Timer(startTime ?? this.startTime, endTime ?? this.endTime);
Timer copyWith({String id, DateTime startTime, DateTime endTime}) {
return Timer(
startTime ?? this.startTime,
endTime ?? this.endTime,
id: id ?? this.id,
);
}
@override
int get hashCode => startTime.hashCode ^ endTime.hashCode;
int get hashCode => id.hashCode ^ startTime.hashCode ^ endTime.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Timer &&
runtimeType == other.runtimeType &&
id == other.id &&
startTime == other.startTime &&
endTime == other.endTime;
TimerEntity toEntity() {
return TimerEntity(startTime, endTime);
return TimerEntity(id, startTime, endTime);
}
static Timer fromEntity(TimerEntity entity) {
return Timer(entity.startTime, entity.endTime);
return Timer(
entity.startTime,
entity.endTime,
id: entity.id ?? Uuid().generateV4(),
);
}
}