Files
game-tracker/lib/data/models/player.dart
gelbeinhalb 66e657235a
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 45s
Pull Request Pipeline / lint (pull_request) Successful in 46s
add deleted attribute
2026-04-30 11:56:15 +02:00

46 lines
1.2 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}';
}
/// 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'],
deleted = json['deleted'] ?? false;
/// Converts the Player instance to a JSON object.
Map<String, dynamic> toJson() => {
'id': id,
'createdAt': createdAt.toIso8601String(),
'name': name,
'description': description,
'deleted': deleted,
};
}