Files
impact/lib/data/models/shot.dart

73 lines
1.6 KiB
Dart

class Shot {
final String id;
final double x; // Relative position (0.0 - 1.0)
final double y; // Relative position (0.0 - 1.0)
final int score;
final String analysisId;
Shot({
required this.id,
required this.x,
required this.y,
required this.score,
required this.analysisId,
});
Shot copyWith({
String? id,
double? x,
double? y,
int? score,
String? analysisId,
}) {
return Shot(
id: id ?? this.id,
x: x ?? this.x,
y: y ?? this.y,
score: score ?? this.score,
analysisId: analysisId ?? this.analysisId,
);
}
Map<String, dynamic> toMap() {
return {
'id': id,
'x': x,
'y': y,
'score': score,
'analysis_id': analysisId,
};
}
factory Shot.fromMap(Map<String, dynamic> map) {
return Shot(
id: map['id'] as String,
x: (map['x'] as num).toDouble(),
y: (map['y'] as num).toDouble(),
score: map['score'] as int,
analysisId: map['analysis_id'] as String? ?? map['session_id'] as String? ?? '',
);
}
@override
String toString() {
return 'Shot(id: $id, x: $x, y: $y, score: $score, analysisId: $analysisId)';
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Shot &&
other.id == id &&
other.x == x &&
other.y == y &&
other.score == score &&
other.analysisId == analysisId;
}
@override
int get hashCode {
return id.hashCode ^ x.hashCode ^ y.hashCode ^ score.hashCode ^ analysisId.hashCode;
}
}