add stats page
All checks were successful
All checks were successful
This commit is contained in:
28
lib/services/data_service/data_service_stats.dart
Normal file
28
lib/services/data_service/data_service_stats.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
part of 'data_service.dart';
|
||||
|
||||
extension DataServiceStats on DataService {
|
||||
Future<void> 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<String, dynamic>) {
|
||||
_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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user