first commit
This commit is contained in:
54
lib/models/time_goal.dart
Normal file
54
lib/models/time_goal.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
class TimeGoal {
|
||||
final int? id;
|
||||
final String goalType; // 'daily_total' 或 'daily_category'
|
||||
final String? category; // 如果是分类目标,指定分类
|
||||
final int targetTime; // 目标时长(秒)
|
||||
final bool isActive;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
|
||||
TimeGoal({
|
||||
this.id,
|
||||
required this.goalType,
|
||||
this.category,
|
||||
required this.targetTime,
|
||||
this.isActive = true,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'goal_type': goalType,
|
||||
'category': category,
|
||||
'target_time': targetTime,
|
||||
'is_active': isActive ? 1 : 0,
|
||||
'created_at': createdAt.millisecondsSinceEpoch ~/ 1000,
|
||||
'updated_at': updatedAt.millisecondsSinceEpoch ~/ 1000,
|
||||
};
|
||||
}
|
||||
|
||||
factory TimeGoal.fromMap(Map<String, dynamic> map) {
|
||||
return TimeGoal(
|
||||
id: map['id'] as int?,
|
||||
goalType: map['goal_type'] as String,
|
||||
category: map['category'] as String?,
|
||||
targetTime: map['target_time'] as int,
|
||||
isActive: (map['is_active'] as int) == 1,
|
||||
createdAt: DateTime.fromMillisecondsSinceEpoch((map['created_at'] as int) * 1000),
|
||||
updatedAt: DateTime.fromMillisecondsSinceEpoch((map['updated_at'] as int) * 1000),
|
||||
);
|
||||
}
|
||||
|
||||
// 格式化目标时长
|
||||
String get formattedTargetTime {
|
||||
final hours = targetTime ~/ 3600;
|
||||
final minutes = (targetTime % 3600) ~/ 60;
|
||||
if (hours > 0) {
|
||||
return '${hours}小时${minutes}分钟';
|
||||
}
|
||||
return '${minutes}分钟';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user