cpd_2022_zi/lib/models/sleep.dart

45 lines
1.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:smoke_cess_app/interface/db_record.dart';
class Sleep implements DatabaseRecord {
final int _sleepQualityValue;
final String _comment;
final DateTime _date;
final TimeOfDay _sleptAt;
final TimeOfDay _wokeUpAt;
Sleep(this._sleepQualityValue, this._comment, this._date, this._sleptAt,
this._wokeUpAt);
DateTime get date => _date;
int get sleepQualitiyValue => _sleepQualityValue;
@override
factory Sleep.fromDatabase(Map<String, dynamic> map) {
DateTime date = DateTime.parse(map['date']);
TimeOfDay sleptAt =
TimeOfDay(hour: map['sleptAtHour'], minute: map['sleptAtMinute']);
TimeOfDay wokeUpAt =
TimeOfDay(hour: map['wokeUpAtHour'], minute: map['wokeUpAtMinute']);
return Sleep(map['value'], map['comment'], date, sleptAt, wokeUpAt);
}
@override
String toCSV() {
return "${_date.toIso8601String()}, $_sleepQualityValue, ${_sleptAt.hour}:${_sleptAt.minute}, ${_wokeUpAt.hour}:${_wokeUpAt.minute}, $_comment";
}
@override
Map<String, dynamic> toMap() {
return {
'value': _sleepQualityValue,
'comment': _comment,
'date': _date.toIso8601String(),
'sleptAtHour': _sleptAt.hour,
'sleptAtMinute': _sleptAt.minute,
'wokeUpAtHour': _wokeUpAt.hour,
'wokeUpAtMinute': _wokeUpAt.minute,
};
}
}