import 'dart:io'; import 'package:device_info_plus/device_info_plus.dart'; import '../../main.dart'; // مفاتيح التخزين (بسيطة) const _kDeviceTierKey = 'deviceTier'; // 'low' | 'mid' | 'high' const _kDeviceTierCheckedAtKey = 'deviceTierTime'; // millisSinceEpoch Future detectAndCacheDeviceTier({bool force = false}) async { // لا تعيد الفحص إذا عملناه خلال آخر 24 ساعة if (!force) { final last = box.read(_kDeviceTierCheckedAtKey); if (last is int) { final dt = DateTime.fromMillisecondsSinceEpoch(last); if (DateTime.now().difference(dt) < const Duration(hours: 24)) { final cached = box.read(_kDeviceTierKey); if (cached is String && cached.isNotEmpty) return cached; // low/mid/high } } } final info = DeviceInfoPlugin(); int score = 0; if (Platform.isAndroid) { final a = await info.androidInfo; final int sdk = a.version.sdkInt ?? 0; final int cores = Platform.numberOfProcessors; final int abisCount = a.supportedAbis.length; final bool isEmu = !(a.isPhysicalDevice ?? true); // SDK (أقدم = أضعف) if (sdk <= 26) score += 3; // 8.0 وأقدم else if (sdk <= 29) score += 2; // 9-10 else if (sdk <= 30) score += 1; // 11 // الأنوية if (cores <= 4) score += 3; else if (cores <= 6) score += 2; else if (cores <= 8) score += 1; // ABI count (القليل غالباً أضعف) if (abisCount <= 1) score += 2; else if (abisCount == 2) score += 1; // محاكي if (isEmu) score += 2; } else { // iOS/منصات أخرى: تقدير سريع بالأنوية فقط final int cores = Platform.numberOfProcessors; if (cores <= 4) score += 3; else if (cores <= 6) score += 2; else if (cores <= 8) score += 1; } // تحويل السكور إلى تصنيف final String tier = (score >= 6) ? 'low' : (score >= 3) ? 'mid' : 'high'; box.write(_kDeviceTierKey, tier); box.write(_kDeviceTierCheckedAtKey, DateTime.now().millisecondsSinceEpoch); return tier; } // للقراءة السريعة وقت ما تحتاج: String getCachedDeviceTier() { final t = box.read(_kDeviceTierKey); if (t is String && t.isNotEmpty) return t; return 'mid'; } bool isLowEnd() => getCachedDeviceTier() == 'low'; bool isMidEnd() => getCachedDeviceTier() == 'mid'; bool isHighEnd() => getCachedDeviceTier() == 'high';