Files
game-tracker/lib/data/models/player.dart
Felix Kirchner fcf845af4d
Some checks failed
Pull Request Pipeline / test (pull_request) Failing after 43s
Pull Request Pipeline / lint (pull_request) Successful in 49s
Implemented name count update in player selection
2026-04-19 23:22:14 +02:00

42 lines
1.0 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;
Player({
String? id,
DateTime? createdAt,
required this.name,
this.nameCount = 0,
String? description,
}) : 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}';
}
/// Creates a Player instance from a JSON object.
Player.fromJson(Map<String, dynamic> json)
: id = json['id'],
createdAt = DateTime.parse(json['createdAt']),
name = json['name'],
nameCount = 0,
description = json['description'];
/// Converts the Player instance to a JSON object.
Map<String, dynamic> toJson() => {
'id': id,
'createdAt': createdAt.toIso8601String(),
'name': name,
'description': description,
};
}