Skip to content

Commit

Permalink
fix isOpen
Browse files Browse the repository at this point in the history
  • Loading branch information
fedecarroz committed Oct 4, 2024
1 parent 61ab38e commit e168b4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/data/models/leaderboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ class Leaderboard extends Equatable {
final LeaderboardUser currentUser;
final List<LeaderboardUser> users;
final List<LeaderboardGroup> groups;
final bool isOpen;

const Leaderboard({
this.currentUser = const LeaderboardUser(),
this.users = const [],
this.groups = const [],
this.isOpen = true,
});

Leaderboard copyWith({
LeaderboardUser? currentUser,
List<LeaderboardUser>? users,
List<LeaderboardGroup>? groups,
bool? isOpen,
}) {
return Leaderboard(
currentUser: currentUser ?? this.currentUser,
users: users ?? this.users,
groups: groups ?? this.groups,
isOpen: isOpen ?? this.isOpen,
);
}

Expand All @@ -39,6 +43,7 @@ class Leaderboard extends Equatable {
(x) => LeaderboardGroup.fromMap(x),
),
),
isOpen: map['isOpen'] as bool? ?? true,
);
}

Expand All @@ -49,5 +54,5 @@ class Leaderboard extends Equatable {
bool get stringify => true;

@override
List<Object> get props => [currentUser, users, groups];
List<Object> get props => [currentUser, users, groups, isOpen];
}
5 changes: 5 additions & 0 deletions lib/data/repo/leaderboard_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ class LeaderboardRepository {
var currentUser = LeaderboardUser();
List<LeaderboardUser> leaderboardUsers = [];
List<LeaderboardGroup> leaderboardGroups = [];
bool isOpen = true;
for (final child in event.snapshot.children) {
if (child.value == null) {
continue;
}
switch (child.key) {
case 'isOpen':
isOpen = child.value as bool;
break;
case 'users':
final map = child.value as Map;

Expand Down Expand Up @@ -107,6 +111,7 @@ class LeaderboardRepository {
currentUser: currentUser,
users: leaderboardUsers,
groups: leaderboardGroups,
isOpen: isOpen,
);
}
}
Expand Down

0 comments on commit e168b4e

Please sign in to comment.