Files
game-tracker/lib/data/models/player.dart
gelbeinhalb 81b73beeef
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 46s
Pull Request Pipeline / lint (pull_request) Successful in 53s
Merge remote-tracking branch 'origin/development' into bug/195-datenbank-onDelete-ueberpruefen
# Conflicts:
#	assets/schema.json
#	lib/data/db/tables/player_match_table.dart
#	lib/data/models/game.dart
2026-05-12 20:19:50 +02:00

74 lines
1.8 KiB
Dart

import 'package:clock/clock.dart';
import 'package:uuid/uuid.dart';
class Player {
final String id;
final DateTime createdAt;
final String name;
int nameCount;
final String description;
final bool deleted;
Player({
String? id,
DateTime? createdAt,
required this.name,
this.nameCount = 0,
String? description,
this.deleted = false,
}) : id = id ?? const Uuid().v4(),
createdAt = createdAt ?? clock.now(),
description = description ?? '';
@override
String toString() {
return 'Player{id: $id, createdAt: $createdAt, name: $name, nameCount: $nameCount, description: $description}';
}
Player copyWith({
String? id,
DateTime? createdAt,
String? name,
int? nameCount,
String? description,
}) {
return Player(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
name: name ?? this.name,
nameCount: nameCount ?? this.nameCount,
description: description ?? this.description,
);
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Player &&
runtimeType == other.runtimeType &&
id == other.id &&
createdAt == other.createdAt &&
name == other.name &&
nameCount == other.nameCount &&
description == other.description;
@override
int get hashCode => Object.hash(id, createdAt, name, nameCount, description);
Player.fromJson(Map<String, dynamic> json)
: id = json['id'],
createdAt = DateTime.parse(json['createdAt']),
name = json['name'],
nameCount = 0,
description = json['description'],
deleted = json['deleted'] ?? false;
Map<String, dynamic> toJson() => {
'id': id,
'createdAt': createdAt.toIso8601String(),
'name': name,
'description': description,
'deleted': deleted,
};
}