85 lines
1.9 KiB
Dart
85 lines
1.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
import 'package:hive/hive.dart';
|
|
|
|
// flutter packages pub run build_runner build
|
|
part 'health.g.dart';
|
|
|
|
@HiveType(typeId: 0)
|
|
class HealthRecord extends HiveObject {
|
|
@HiveField(0)
|
|
int id;
|
|
|
|
@HiveField(1)
|
|
String sportProject;
|
|
|
|
@HiveField(2)
|
|
num sportDuration;
|
|
|
|
@HiveField(3)
|
|
num weight;
|
|
|
|
@HiveField(4)
|
|
String sleepStartTime;
|
|
|
|
@HiveField(5)
|
|
String sleepEndTime;
|
|
|
|
@HiveField(7)
|
|
String date;
|
|
|
|
HealthRecord({
|
|
required this.id,
|
|
required this.sportProject,
|
|
required this.sportDuration,
|
|
required this.weight,
|
|
required this.sleepStartTime,
|
|
required this.sleepEndTime,
|
|
required this.date,
|
|
});
|
|
|
|
static HealthRecord getEmpty(String date) {
|
|
return HealthRecord(
|
|
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
|
sportProject: '',
|
|
sportDuration: 0,
|
|
weight: 0,
|
|
sleepStartTime: '',
|
|
sleepEndTime: '',
|
|
date: date,
|
|
);
|
|
}
|
|
|
|
HealthRecord copyWith({
|
|
int? id,
|
|
num? weight,
|
|
String? sportProject,
|
|
num? sportDuration,
|
|
String? sleepStartTime,
|
|
String? sleepEndTime,
|
|
String? date,
|
|
}) {
|
|
return HealthRecord(
|
|
id: id ?? this.id,
|
|
date: date ?? this.date,
|
|
weight: weight ?? this.weight,
|
|
sportProject: sportProject ?? this.sportProject,
|
|
sportDuration: sportDuration ?? this.sportDuration,
|
|
sleepStartTime: sleepStartTime ?? this.sleepStartTime,
|
|
sleepEndTime: sleepEndTime ?? this.sleepEndTime
|
|
);
|
|
}
|
|
}
|
|
|
|
enum RecordType {
|
|
weight('体重', FontAwesomeIcons.weightScale, Color(0xFFF59E0B)),
|
|
sport('运动', FontAwesomeIcons.personRunning, Color(0xFF38BDF8)),
|
|
sleep('睡眠', FontAwesomeIcons.moon, Color(0xFF10B981));
|
|
|
|
final String title;
|
|
final IconData icon;
|
|
final Color color;
|
|
|
|
const RecordType(this.title, this.icon, this.color);
|
|
}
|