25-8-9-1
This commit is contained in:
39
lib/controller/functions/battery_status.dart
Normal file
39
lib/controller/functions/battery_status.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:battery_plus/battery_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class BatteryNotifier {
|
||||
static final Battery _battery = Battery();
|
||||
static int? _lastNotifiedLevel;
|
||||
|
||||
static Future<void> checkBatteryAndNotify() async {
|
||||
try {
|
||||
final int batteryLevel = await _battery.batteryLevel;
|
||||
|
||||
// ✅ لا تكرر الإشعار إذا الفرق قليل
|
||||
if (_lastNotifiedLevel != null &&
|
||||
(batteryLevel >= _lastNotifiedLevel! - 2)) return;
|
||||
|
||||
if (batteryLevel <= 30) {
|
||||
Color backgroundColor = Colors.yellow;
|
||||
if (batteryLevel <= 20) {
|
||||
backgroundColor = Colors.red;
|
||||
}
|
||||
|
||||
Get.snackbar(
|
||||
"⚠️ تنبيه البطارية", // العنوان
|
||||
"مستوى البطارية: $batteryLevel٪", // النص
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: backgroundColor,
|
||||
colorText: Colors.white,
|
||||
duration: const Duration(seconds: 10), // مدة الظهور
|
||||
margin: const EdgeInsets.all(10),
|
||||
);
|
||||
|
||||
_lastNotifiedLevel = batteryLevel;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Battery check error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,9 +43,9 @@ class CRUD {
|
||||
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
|
||||
},
|
||||
);
|
||||
print(response.request);
|
||||
Log.print('response.body: ${response.body}');
|
||||
print(payload);
|
||||
// print(response.request);
|
||||
// Log.print('response.body: ${response.body}');
|
||||
// print(payload);
|
||||
if (response.statusCode == 200) {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
if (jsonData['status'] == 'success') {
|
||||
@@ -94,9 +94,9 @@ class CRUD {
|
||||
'X-HMAC-Auth': hmac.toString(),
|
||||
},
|
||||
);
|
||||
Log.print('response.request: ${response.request}');
|
||||
Log.print('response.body: ${response.body}');
|
||||
print(payload);
|
||||
// Log.print('response.request: ${response.request}');
|
||||
// Log.print('response.body: ${response.body}');
|
||||
// print(payload);
|
||||
if (response.statusCode == 200) {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
if (jsonData['status'] == 'success') {
|
||||
@@ -145,9 +145,9 @@ class CRUD {
|
||||
'X-HMAC-Auth': hmac.toString(),
|
||||
},
|
||||
);
|
||||
Log.print('response.request:${response.request}');
|
||||
Log.print('response.body: ${response.body}');
|
||||
Log.print('payload:$payload');
|
||||
// Log.print('response.request:${response.request}');
|
||||
// Log.print('response.body: ${response.body}');
|
||||
// Log.print('payload:$payload');
|
||||
if (response.statusCode == 200) {
|
||||
try {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
@@ -203,9 +203,9 @@ class CRUD {
|
||||
// 'Authorization': 'Bearer ${box.read(BoxName.jwt)}'
|
||||
},
|
||||
);
|
||||
print(response.request);
|
||||
Log.print('response.body: ${response.body}');
|
||||
print(payload);
|
||||
// print(response.request);
|
||||
// Log.print('response.body: ${response.body}');
|
||||
// print(payload);
|
||||
if (response.statusCode == 200) {
|
||||
try {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
|
||||
205
lib/controller/functions/device_analyzer.dart
Normal file
205
lib/controller/functions/device_analyzer.dart
Normal file
@@ -0,0 +1,205 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'performance_test.dart'; // Make sure this path is correct
|
||||
|
||||
/// Analyzes various device hardware and software aspects to generate a compatibility score.
|
||||
/// This class provides a standardized output for the UI to consume easily.
|
||||
class DeviceAnalyzer {
|
||||
final DeviceInfoPlugin _deviceInfo = DeviceInfoPlugin();
|
||||
|
||||
/// Reads the total RAM from the system's meminfo file.
|
||||
/// Returns the value in Megabytes (MB).
|
||||
Future<double> _readTotalRamMB() async {
|
||||
try {
|
||||
final file = File('/proc/meminfo');
|
||||
if (!await file.exists()) return 0.0;
|
||||
final lines = await file.readAsLines();
|
||||
for (var line in lines) {
|
||||
if (line.startsWith('MemTotal')) {
|
||||
// Extracts the numeric value from the line.
|
||||
final kb = int.tryParse(RegExp(r'\d+').stringMatch(line) ?? '0') ?? 0;
|
||||
return kb / 1024.0; // Convert from Kilobytes to Megabytes
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('❌ Error reading total RAM: $e');
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/// Reads the current RAM usage percentage from the system's meminfo file.
|
||||
Future<double> _readUsedRamPercent() async {
|
||||
try {
|
||||
final file = File('/proc/meminfo');
|
||||
if (!await file.exists()) return 0.0;
|
||||
final lines = await file.readAsLines();
|
||||
int? total, available;
|
||||
for (var line in lines) {
|
||||
if (line.startsWith('MemTotal')) {
|
||||
total = int.tryParse(RegExp(r'\d+').stringMatch(line) ?? '');
|
||||
} else if (line.startsWith('MemAvailable')) {
|
||||
available = int.tryParse(RegExp(r'\d+').stringMatch(line) ?? '');
|
||||
}
|
||||
}
|
||||
if (total != null && available != null && total > 0) {
|
||||
final used = total - available;
|
||||
return (used / total) * 100.0;
|
||||
}
|
||||
} catch (e) {
|
||||
print('❌ Error reading used RAM: $e');
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/// The main analysis function that runs all checks.
|
||||
Future<Map<String, dynamic>> analyzeDevice() async {
|
||||
List<Map<String, dynamic>> details = [];
|
||||
|
||||
if (!Platform.isAndroid) {
|
||||
return {
|
||||
'score': 0,
|
||||
'details': [
|
||||
{
|
||||
'label': 'النظام غير مدعوم',
|
||||
'status': false,
|
||||
'achieved_score': 0,
|
||||
'max_score': 100
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
final info = await _deviceInfo.androidInfo;
|
||||
final data = info.data;
|
||||
final features = List<String>.from(data['systemFeatures'] ?? []);
|
||||
|
||||
// 1. Android Version (Max: 10 points)
|
||||
final version =
|
||||
int.tryParse(info.version.release?.split('.').first ?? '0') ?? 0;
|
||||
final int androidScore = version >= 9 ? 10 : 0;
|
||||
details.add({
|
||||
'label': 'إصدار أندرويد ${info.version.release}',
|
||||
'status': androidScore > 0,
|
||||
'achieved_score': androidScore,
|
||||
'max_score': 10,
|
||||
});
|
||||
|
||||
// 2. Total RAM (Max: 10 points)
|
||||
final totalRam = await _readTotalRamMB();
|
||||
int ramScore;
|
||||
if (totalRam >= 8000) {
|
||||
ramScore = 10;
|
||||
} else if (totalRam >= 4000) {
|
||||
ramScore = 5;
|
||||
} else if (totalRam >= 3000) {
|
||||
ramScore = 3;
|
||||
} else {
|
||||
ramScore = 0;
|
||||
}
|
||||
details.add({
|
||||
'label': 'إجمالي الرام ${totalRam.toStringAsFixed(0)} ميجابايت',
|
||||
'status': ramScore >= 5,
|
||||
'achieved_score': ramScore,
|
||||
'max_score': 10,
|
||||
});
|
||||
|
||||
// 3. CPU Cores (Max: 10 points)
|
||||
final cores = Platform.numberOfProcessors;
|
||||
int coreScore = cores >= 6 ? 10 : (cores >= 4 ? 5 : 0);
|
||||
details.add({
|
||||
'label': 'أنوية المعالج ($cores)',
|
||||
'status': coreScore >= 5,
|
||||
'achieved_score': coreScore,
|
||||
'max_score': 10,
|
||||
});
|
||||
|
||||
// 4. Free Storage (Max: 5 points)
|
||||
final freeBytes = data['freeDiskSize'] ?? 0;
|
||||
final freeGB = freeBytes / (1024 * 1024 * 1024);
|
||||
int storeScore = freeGB >= 5 ? 5 : (freeGB >= 2 ? 3 : 0);
|
||||
details.add({
|
||||
'label': 'المساحة الحرة ${freeGB.toStringAsFixed(1)} جيجابايت',
|
||||
'status': storeScore >= 3,
|
||||
'achieved_score': storeScore,
|
||||
'max_score': 5,
|
||||
});
|
||||
|
||||
// 5. GPS + Gyroscope Sensors (Max: 10 points)
|
||||
bool okSensors = features.contains('android.hardware.location.gps') &&
|
||||
features.contains('android.hardware.sensor.gyroscope');
|
||||
final int sensorScore = okSensors ? 10 : 0;
|
||||
details.add({
|
||||
'label': 'حساسات GPS و Gyroscope',
|
||||
'status': okSensors,
|
||||
'achieved_score': sensorScore,
|
||||
'max_score': 10,
|
||||
});
|
||||
|
||||
// 6. Storage Write Speed (Max: 20 points)
|
||||
final writeSpeed = await PerformanceTester.testStorageWriteSpeed();
|
||||
int writeScore;
|
||||
if (writeSpeed >= 30) {
|
||||
writeScore = 20;
|
||||
} else if (writeSpeed >= 15) {
|
||||
writeScore = 15;
|
||||
} else if (writeSpeed >= 5) {
|
||||
writeScore = 10;
|
||||
} else {
|
||||
writeScore = 5;
|
||||
}
|
||||
details.add({
|
||||
'label': 'سرعة الكتابة (${writeSpeed.toStringAsFixed(1)} MB/s)',
|
||||
'status': writeScore >= 10,
|
||||
'achieved_score': writeScore,
|
||||
'max_score': 20,
|
||||
});
|
||||
|
||||
// 7. CPU Compute Speed (Max: 20 points)
|
||||
final cpuTime = await PerformanceTester.testCPUSpeed();
|
||||
int cpuScore;
|
||||
if (cpuTime <= 1.0) {
|
||||
cpuScore = 20;
|
||||
} else if (cpuTime <= 2.5) {
|
||||
cpuScore = 15;
|
||||
} else if (cpuTime <= 4.0) {
|
||||
cpuScore = 10;
|
||||
} else {
|
||||
cpuScore = 5;
|
||||
}
|
||||
details.add({
|
||||
'label': 'سرعة المعالجة (${cpuTime.toStringAsFixed(2)} ثانية)',
|
||||
'status': cpuScore >= 10,
|
||||
'achieved_score': cpuScore,
|
||||
'max_score': 20,
|
||||
});
|
||||
|
||||
// 8. Memory Pressure (Max: 15 points)
|
||||
final usedPercent = await _readUsedRamPercent();
|
||||
int memScore;
|
||||
if (usedPercent <= 60) {
|
||||
memScore = 15;
|
||||
} else if (usedPercent <= 80) {
|
||||
memScore = 10;
|
||||
} else if (usedPercent <= 90) {
|
||||
memScore = 5;
|
||||
} else {
|
||||
memScore = 0;
|
||||
}
|
||||
details.add({
|
||||
'label': 'استخدام الرام الحالي (${usedPercent.toStringAsFixed(0)}%)',
|
||||
'status': memScore >= 10,
|
||||
'achieved_score': memScore,
|
||||
'max_score': 15,
|
||||
});
|
||||
|
||||
// Calculate the final total score by summing up the achieved scores.
|
||||
final totalScore = details.fold<int>(
|
||||
0, (sum, item) => sum + (item['achieved_score'] as int));
|
||||
|
||||
return {
|
||||
'score': totalScore.clamp(0, 100),
|
||||
'details': details,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
|
||||
import 'package:sefer_driver/constant/box_name.dart';
|
||||
import 'package:sefer_driver/constant/info.dart';
|
||||
@@ -15,7 +14,6 @@ import 'package:sefer_driver/controller/firebase/local_notification.dart';
|
||||
import 'package:sefer_driver/controller/functions/crud.dart';
|
||||
import 'package:sefer_driver/env/env.dart';
|
||||
import 'package:sefer_driver/main.dart';
|
||||
import 'package:sefer_driver/views/home/Captin/home_captain/home_captin.dart';
|
||||
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
|
||||
import 'package:sefer_driver/views/widgets/mydialoug.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -565,7 +563,7 @@ class AI extends GetxController {
|
||||
|
||||
Future<void> pickAndSendImage(String type) async {
|
||||
final picker = ImagePicker();
|
||||
final pickedImage = await picker.pickImage(source: ImageSource.gallery);
|
||||
final pickedImage = await picker.pickImage(source: ImageSource.camera);
|
||||
if (pickedImage != null) {
|
||||
image = File(pickedImage.path);
|
||||
// Crop the image
|
||||
|
||||
@@ -13,6 +13,7 @@ import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
import '../home/captin/home_captain_controller.dart';
|
||||
import '../home/payment/captain_wallet_controller.dart';
|
||||
import 'battery_status.dart';
|
||||
import 'crud.dart';
|
||||
import 'encrypt_decrypt.dart';
|
||||
|
||||
@@ -84,6 +85,7 @@ class LocationController extends GetxController {
|
||||
_locationTimer =
|
||||
Timer.periodic(const Duration(seconds: 5), (timer) async {
|
||||
try {
|
||||
await BatteryNotifier.checkBatteryAndNotify();
|
||||
totalPoints =
|
||||
Get.find<CaptainWalletController>().totalPoints.toString();
|
||||
isActive = Get.find<HomeCaptainController>().isActive;
|
||||
|
||||
43
lib/controller/functions/performance_test.dart
Normal file
43
lib/controller/functions/performance_test.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'dart:io';
|
||||
|
||||
class PerformanceTester {
|
||||
/// ✅ فحص سرعة الكتابة إلى التخزين (Storage Write Speed) بوحدة MB/s
|
||||
static Future<double> testStorageWriteSpeed() async {
|
||||
try {
|
||||
final tempDir = Directory.systemTemp;
|
||||
final testFile = File('${tempDir.path}/speed_test.txt');
|
||||
final data = List<int>.filled(1024 * 1024 * 5, 0); // 5MB
|
||||
|
||||
final stopwatch = Stopwatch()..start();
|
||||
await testFile.writeAsBytes(data, flush: true);
|
||||
stopwatch.stop();
|
||||
|
||||
await testFile.delete();
|
||||
|
||||
double seconds = stopwatch.elapsedMilliseconds / 1000;
|
||||
if (seconds == 0) seconds = 0.001;
|
||||
|
||||
final speed = 5 / seconds;
|
||||
return double.parse(speed.toStringAsFixed(2));
|
||||
} catch (e) {
|
||||
print("❌ Storage write error: $e");
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/// ✅ فحص سرعة المعالج (CPU Compute Speed) بوحدة الثواني
|
||||
static Future<double> testCPUSpeed() async {
|
||||
try {
|
||||
final stopwatch = Stopwatch()..start();
|
||||
double x = 0;
|
||||
for (int i = 0; i < 100000000; i++) {
|
||||
x += i * 0.000001;
|
||||
}
|
||||
stopwatch.stop();
|
||||
return stopwatch.elapsedMilliseconds / 1000.0;
|
||||
} catch (e) {
|
||||
print("❌ CPU compute error: $e");
|
||||
return 999.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user