Line data Source code
1 : import 'package:amadeus_proto/models/level.dart';
2 : import 'package:collection/collection.dart';
3 :
4 : class Profile {
5 : final String id;
6 : final String username;
7 : final String? bio;
8 : final int coins;
9 : final String? imageUrl;
10 : final Level level;
11 : final int lives;
12 : final List<DateTime> streakDays;
13 :
14 3 : Profile({
15 : required this.id,
16 : required this.username,
17 : required this.bio,
18 : this.imageUrl,
19 : required this.level,
20 : required this.lives,
21 : required this.coins,
22 : required this.streakDays,
23 : });
24 :
25 3 : factory Profile.fromJson(Map<String, dynamic> json) {
26 3 : return Profile(
27 3 : id: json['id'] as String,
28 3 : username: json['username'] as String,
29 3 : bio: json['biography'] as String?,
30 3 : imageUrl: json['imageUrl'] as String?,
31 9 : level: Level(exp: json['xp'] as int, level: json['level'] as int),
32 3 : lives: json['lives'] as int,
33 3 : coins: json['coins'] as int,
34 3 : streakDays: (json['streakDays'] as List<dynamic>)
35 9 : .map((e) => DateTime.parse(e as String))
36 3 : .toList(),
37 : );
38 : }
39 :
40 0 : Map<String, dynamic> toJson() {
41 0 : return {
42 0 : 'id': id,
43 0 : 'username': username,
44 0 : 'biography': bio,
45 0 : 'imageUrl': imageUrl,
46 0 : 'level': level.level,
47 0 : 'exp': level.exp,
48 0 : 'lives': lives,
49 0 : 'coins': coins,
50 0 : 'streakDays': streakDays.map((e) => e.toIso8601String()).toList(),
51 : };
52 : }
53 :
54 1 : @override
55 : bool operator ==(Object other) {
56 : if (identical(this, other)) return true;
57 1 : if (other is! Profile) return false;
58 3 : return id == other.id &&
59 3 : username == other.username &&
60 3 : bio == other.bio &&
61 3 : coins == other.coins &&
62 3 : imageUrl == other.imageUrl &&
63 3 : level == other.level &&
64 3 : lives == other.lives &&
65 3 : const ListEquality().equals(streakDays, other.streakDays);
66 : }
67 :
68 0 : @override
69 : int get hashCode =>
70 0 : id.hashCode ^
71 0 : username.hashCode ^
72 0 : (bio?.hashCode ?? 0) ^
73 0 : coins.hashCode ^
74 0 : (imageUrl?.hashCode ?? 0) ^
75 0 : level.hashCode ^
76 0 : lives.hashCode ^
77 0 : const ListEquality().hash(streakDays);
78 : }
|