kettlebell-tracker/lib/models/training_session.dart
2025-06-16 18:56:34 +02:00

55 lines
1.3 KiB
Dart

class TrainingSession {
final int? id;
final DateTime date;
final int sets;
final double weightLeft;
final double weightRight;
final int repsPerSet;
final int duration; // in seconds
final String notes;
TrainingSession({
this.id,
required this.date,
required this.sets,
required this.weightLeft,
required this.weightRight,
required this.repsPerSet,
required this.duration,
required this.notes,
});
// Convert a TrainingSession into a Map. The keys must correspond to the names of the
// columns in the database.
Map<String, dynamic> toMap() {
return {
'id': id,
'date': date.toIso8601String(),
'sets': sets,
'weightLeft': weightLeft,
'weightRight': weightRight,
'repsPerSet': repsPerSet,
'duration': duration,
'notes': notes,
};
}
// Implement fromMap
factory TrainingSession.fromMap(Map<String, dynamic> map) {
return TrainingSession(
id: map['id'],
date: DateTime.parse(map['date']),
sets: map['sets'],
weightLeft: map['weightLeft'],
weightRight: map['weightRight'],
repsPerSet: map['repsPerSet'],
duration: map['duration'],
notes: map['notes'],
);
}
@override
String toString() {
return 'TrainingSession{id: $id, date: $date, sets: $sets, notes: $notes}';
}
}