feat:增加数据存储
This commit is contained in:
82
lib/models/health.dart
Normal file
82
lib/models/health.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
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(6)
|
||||
num sleepDuration;
|
||||
|
||||
@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.sleepDuration,
|
||||
required this.date,
|
||||
});
|
||||
|
||||
static HealthRecord getEmpty() {
|
||||
return HealthRecord(
|
||||
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
sportProject: '',
|
||||
sportDuration: 0,
|
||||
weight: 0,
|
||||
sleepStartTime: '',
|
||||
sleepEndTime: '',
|
||||
sleepDuration: 0,
|
||||
date: '',
|
||||
);
|
||||
}
|
||||
|
||||
static HealthRecord getDefault() {
|
||||
return HealthRecord(
|
||||
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
sportProject: '跑步',
|
||||
sportDuration: 30,
|
||||
weight: 70,
|
||||
sleepStartTime: '',
|
||||
sleepEndTime: '',
|
||||
sleepDuration: 0,
|
||||
date: '',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user