add new featurs like realtime 2026-5-10-25

This commit is contained in:
Hamza-Ayed
2026-05-10 17:38:33 +03:00
parent 0d9fab31bd
commit e17866aa2f
86 changed files with 1939 additions and 10 deletions

View File

@@ -0,0 +1,62 @@
import 'dart:async';
import 'dart:convert';
import 'package:get/get.dart';
import 'package:sefer_admin1/constant/links.dart';
import 'package:sefer_admin1/controller/functions/crud.dart';
import '../../print.dart';
class DashboardV2Controller extends GetxController {
bool isLoading = true;
Map<String, dynamic> realtimeData = {};
List<dynamic> smartAlerts = [];
Timer? _timer;
@override
void onInit() {
super.onInit();
fetchRealtimeData();
fetchSmartAlerts();
// Auto refresh every 30 seconds
_timer = Timer.periodic(const Duration(seconds: 30), (timer) {
fetchRealtimeData();
fetchSmartAlerts();
});
}
@override
void onClose() {
_timer?.cancel();
super.onClose();
}
Future<void> fetchRealtimeData() async {
try {
var res = await CRUD().get(link: AppLink.realtimeDashboardV2, payload: {});
if (res != 'failure' && res != null) {
var d = res is String ? jsonDecode(res) : res;
if (d['status'] == 'success') {
realtimeData = d['message'];
isLoading = false;
update();
}
}
} catch (e) {
Log.print('Error fetching realtime dashboard: $e');
}
}
Future<void> fetchSmartAlerts() async {
try {
var res = await CRUD().get(link: AppLink.smartAlertsV2, payload: {});
if (res != 'failure' && res != null) {
var d = res is String ? jsonDecode(res) : res;
if (d['status'] == 'success') {
smartAlerts = d['message'];
update();
}
}
} catch (e) {
Log.print('Error fetching smart alerts: $e');
}
}
}