added leaderboards (without clickthrough to filtered by author - later)
This commit is contained in:
@@ -38,7 +38,7 @@ class QuoteProvider extends ChangeNotifier {
|
||||
return filtered;
|
||||
}
|
||||
|
||||
Map<String, int> get authorCounts {
|
||||
Map<String, int> get _authorCounts {
|
||||
final counts = <String, int>{};
|
||||
|
||||
for (var quote in filteredQuotes) {
|
||||
@@ -52,6 +52,23 @@ class QuoteProvider extends ChangeNotifier {
|
||||
return counts;
|
||||
}
|
||||
|
||||
List<MapEntry<String, int>> get sortedAuthorCounts {
|
||||
final counts = <String, int>{};
|
||||
|
||||
for (var quote in filteredQuotes) {
|
||||
counts.update(
|
||||
quote.author,
|
||||
(value) => value + 1,
|
||||
ifAbsent: () => 1,
|
||||
);
|
||||
}
|
||||
|
||||
final list = counts.entries.toList()
|
||||
..sort((a, b) => b.value.compareTo(a.value)); // descending
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
final QuoteRepository repo = QuoteRepository();
|
||||
|
||||
int filterBy = 0; // 0 = by author, 1 = by quote
|
||||
@@ -191,4 +208,30 @@ class QuoteProvider extends ChangeNotifier {
|
||||
final file = File('${dir.path}/hlasky_$datetime.txt');
|
||||
await file.writeAsString("${filteredQuotes.join("\n")}\n");
|
||||
}
|
||||
|
||||
Color getLeaderboardEntryBgColor(BuildContext context, int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return Colors.yellow.shade300; // 1st place
|
||||
case 1:
|
||||
return Colors.grey.shade300; // 2nd place
|
||||
case 2:
|
||||
return Colors.brown.shade300; // 3rd place
|
||||
default:
|
||||
return Theme.of(context).cardColor; // default for all other entries
|
||||
}
|
||||
}
|
||||
|
||||
Color getLeaderboardEntryFgColor(BuildContext context, int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return Colors.black; // 1st place
|
||||
case 1:
|
||||
return Colors.black; // 2nd place
|
||||
case 2:
|
||||
return Colors.black; // 3rd place
|
||||
default:
|
||||
return Colors.white; // default for all other entries
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user