import 'package:flutter/cupertino.dart'; import 'package:flutter_common/flutter_common.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) String date; @HiveField(1) String sportProject; @HiveField(2) num sportDuration; @HiveField(3) num weight; @HiveField(4) String sleepStartTime; @HiveField(5) String sleepEndTime; HealthRecord({ required this.sportProject, required this.sportDuration, required this.weight, required this.sleepStartTime, required this.sleepEndTime, required this.date, }); static HealthRecord getEmpty(DateTime date) { return HealthRecord( sportProject: '', sportDuration: 0, weight: 0, sleepStartTime: '', sleepEndTime: '', date: formatDate(date), ); } HealthRecord copyWith({ int? id, double? weight, String? sportProject, double? sportDuration, String? sleepStartTime, String? sleepEndTime, String? date, }) { return HealthRecord( 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), 'Kg'), sport('运动', FontAwesomeIcons.personRunning, Color(0xFF38BDF8), '分钟'), sleep('睡眠', FontAwesomeIcons.moon, Color(0xFF10B981), '小时'); final String title; final IconData icon; final Color color; final String unit; const RecordType(this.title, this.icon, this.color, this.unit); }