2023-02-16 01:59:15 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:smoke_cess_app/interface/db_record.dart';
|
|
|
|
|
|
|
|
class Sleep implements DatabaseRecord {
|
2023-02-25 18:54:23 +01:00
|
|
|
final int _sleepQualityValue;
|
2023-02-16 01:59:15 +01:00
|
|
|
final String _comment;
|
|
|
|
final DateTime _date;
|
|
|
|
final TimeOfDay _sleepedAt;
|
|
|
|
final TimeOfDay _wokeUpAt;
|
|
|
|
|
|
|
|
Sleep(this._sleepQualityValue, this._comment, this._date, this._sleepedAt,
|
|
|
|
this._wokeUpAt);
|
|
|
|
|
2023-02-25 18:54:23 +01:00
|
|
|
@override
|
|
|
|
factory Sleep.fromDatabase(Map<String, dynamic> map) {
|
|
|
|
DateTime date = DateTime.parse(map['date']);
|
|
|
|
TimeOfDay sleepedAt =
|
|
|
|
TimeOfDay(hour: map['sleepedAtHour'], minute: map['sleepedAtMinute']);
|
|
|
|
TimeOfDay wokeUpAt =
|
|
|
|
TimeOfDay(hour: map['wokeUpAtHour'], minute: map['wokeUpAtMinute']);
|
|
|
|
return Sleep(map['value'], map['comment'], date, sleepedAt, wokeUpAt);
|
|
|
|
}
|
|
|
|
|
2023-02-16 01:59:15 +01:00
|
|
|
@override
|
|
|
|
String toCSV() {
|
2023-02-25 18:54:23 +01:00
|
|
|
return "${_date.toIso8601String()}, $_sleepQualityValue, ${_sleepedAt.hour}:${_sleepedAt.minute}, ${_wokeUpAt.hour}:${_wokeUpAt.minute}, $_comment";
|
2023-02-16 01:59:15 +01:00
|
|
|
}
|
2023-02-22 01:28:01 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
2023-02-25 18:54:23 +01:00
|
|
|
'value': _sleepQualityValue,
|
2023-02-22 01:28:01 +01:00
|
|
|
'comment': _comment,
|
2023-02-25 18:54:23 +01:00
|
|
|
'date': _date.toIso8601String(),
|
|
|
|
'sleepedAtHour': _sleepedAt.hour,
|
|
|
|
'sleepedAtMinute': _sleepedAt.minute,
|
|
|
|
'wokeUpAtHour': _wokeUpAt.hour,
|
|
|
|
'wokeUpAtMinute': _wokeUpAt.minute,
|
2023-02-22 01:28:01 +01:00
|
|
|
};
|
|
|
|
}
|
2023-02-16 01:59:15 +01:00
|
|
|
}
|