Update: 2026-06-15 01:37:40

This commit is contained in:
Hamza-Ayed
2026-06-15 01:37:41 +03:00
parent f021ba5a35
commit 2321b78244
164 changed files with 1356 additions and 1560 deletions

View File

@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:siro_driver/constant/links.dart';
import 'package:siro_driver/main.dart';
import 'package:siro_driver/controller/functions/crud.dart';
import 'package:siro_driver/print.dart';
import 'package:siro_driver/views/widgets/error_snakbar.dart';
@@ -50,12 +51,35 @@ class VideoController extends GetxController {
super.onClose();
}
void fetchVideos() async {
void fetchVideos({bool force = false}) async {
final String cacheKey = 'video_list_cache';
final String lastFetchKey = 'video_last_fetch';
if (!force) {
String? cachedVideos = box.read(cacheKey);
String? lastFetchStr = box.read(lastFetchKey);
if (cachedVideos != null && lastFetchStr != null) {
try {
DateTime lastFetch = DateTime.parse(lastFetchStr);
if (DateTime.now().difference(lastFetch).inHours < 3) {
videos = jsonDecode(cachedVideos);
isLoading(false);
update();
return;
}
} catch (e) {
Log.print('⚠️ [VideoController] Failed to parse cache: $e');
}
}
}
try {
var res = await CRUD().get(link: apiUrl, payload: {});
if (res != 'failure') {
videos = jsonDecode(res)['message'];
// Log.print('videos: ${videos}');
box.write(cacheKey, jsonEncode(videos));
box.write(lastFetchKey, DateTime.now().toIso8601String());
update();
} else {
mySnackeBarError('');