part of 'data_service.dart'; extension DataServiceStats on DataService { Future fetchAboutStats({bool force = false}) async { if (_isAboutStatsLoading) return; if (!force && _aboutStats != null) return; _isAboutStatsLoading = true; _notifyAsync(); try { final json = await api.get('/stats/about'); if (json is Map) { _aboutStats = StatsAbout.fromJson(json); } else if (json is Map) { _aboutStats = StatsAbout.fromJson( json.map((key, value) => MapEntry(key.toString(), value)), ); } else { throw Exception('Unexpected stats response: $json'); } } catch (e) { debugPrint('Failed to fetch about stats: $e'); _aboutStats = null; } finally { _isAboutStatsLoading = false; _notifyAsync(); } } Future fetchFriendsLeaderboard() async { if (_isFriendsLeaderboardLoading) return; _isFriendsLeaderboardLoading = true; _notifyAsync(); try { final json = await api.get('/stats/leaderboard/friends'); List? list; if (json is List) { list = json; } else if (json is Map) { for (final key in ['leaderboard', 'data', 'items', 'results']) { final value = json[key]; if (value is List) { list = value; break; } } } _friendsLeaderboard = list ?.whereType() .map((e) => LeaderboardEntry.fromJson( e.map((k, v) => MapEntry(k.toString(), v)), )) .toList() ?? const []; } catch (e) { debugPrint('Failed to fetch friends leaderboard: $e'); _friendsLeaderboard = []; } finally { _isFriendsLeaderboardLoading = false; _notifyAsync(); } } }