25-8-9-1
This commit is contained in:
248
lib/device_compatibility_page.dart
Normal file
248
lib/device_compatibility_page.dart
Normal file
@@ -0,0 +1,248 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'controller/functions/device_analyzer.dart';
|
||||
|
||||
// --- CompatibilityDetailCard Widget (Updated to use 'max_score') ---
|
||||
class CompatibilityDetailCard extends StatelessWidget {
|
||||
final Map<String, dynamic> detail;
|
||||
const CompatibilityDetailCard({super.key, required this.detail});
|
||||
|
||||
Color _getStatusColor(bool status, int achieved, int max) {
|
||||
if (!status) return Colors.red.shade400;
|
||||
if (achieved < max) return Colors.orange.shade600;
|
||||
return Colors.teal;
|
||||
}
|
||||
|
||||
IconData _getIconForLabel(String label) {
|
||||
if (label.contains('رام')) return Icons.memory;
|
||||
if (label.contains('معالج') || label.contains('CPU')) {
|
||||
return Icons.developer_board;
|
||||
}
|
||||
if (label.contains('تخزين') || label.contains('كتابة')) {
|
||||
return Icons.sd_storage_outlined;
|
||||
}
|
||||
if (label.contains('أندرويد')) return Icons.android;
|
||||
if (label.contains('خدمات')) return Icons.g_mobiledata;
|
||||
if (label.contains('حساسات') || label.contains('Gyroscope')) {
|
||||
return Icons.sensors;
|
||||
}
|
||||
return Icons.smartphone;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool status = detail['status'] ?? false;
|
||||
final String label = detail['label'] ?? "";
|
||||
final int achievedScore = detail['achieved_score'] ?? 0;
|
||||
// Corrected to use 'max_score' from the analyzer
|
||||
final int maxScore = detail['max_score'] ?? 1;
|
||||
final Color color = _getStatusColor(status, achievedScore, maxScore);
|
||||
final double progress =
|
||||
(maxScore > 0) ? (achievedScore / maxScore).clamp(0.0, 1.0) : 0.0;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 7),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.08),
|
||||
blurRadius: 15,
|
||||
offset: const Offset(0, 5),
|
||||
)
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(_getIconForLabel(label),
|
||||
color: Colors.grey.shade600, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: Colors.grey.shade800,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
// Corrected to display points out of max_score
|
||||
Text(
|
||||
"$achievedScore/$maxScore نقطة",
|
||||
style: TextStyle(
|
||||
color: color, fontWeight: FontWeight.bold, fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
LinearProgressIndicator(
|
||||
value: progress,
|
||||
backgroundColor: Colors.grey.shade200,
|
||||
color: color,
|
||||
minHeight: 6,
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Main Page Widget ---
|
||||
class DeviceCompatibilityPage extends StatefulWidget {
|
||||
const DeviceCompatibilityPage({super.key});
|
||||
@override
|
||||
State<DeviceCompatibilityPage> createState() =>
|
||||
_DeviceCompatibilityPageState();
|
||||
}
|
||||
|
||||
class _DeviceCompatibilityPageState extends State<DeviceCompatibilityPage> {
|
||||
int score = 0;
|
||||
List<Map<String, dynamic>> details = [];
|
||||
bool isLoading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initializePage();
|
||||
}
|
||||
|
||||
Future<void> _initializePage() async {
|
||||
// await BatteryNotifier.checkBatteryAndNotify();
|
||||
final result = await DeviceAnalyzer().analyzeDevice();
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
score = result['score'];
|
||||
details = List<Map<String, dynamic>>.from(result['details']);
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Color _getColorForScore(int value) {
|
||||
if (value >= 80) return Colors.teal;
|
||||
if (value >= 60) return Colors.orange.shade700;
|
||||
return Colors.red.shade600;
|
||||
}
|
||||
|
||||
String _getScoreMessage(int value) {
|
||||
if (value >= 80) return "جهازك يقدم أداءً ممتازاً";
|
||||
if (value >= 60) return "جهازك جيد ومناسب جداً";
|
||||
if (value >= 40) return "متوافق، قد تلاحظ بعض البطء";
|
||||
return "قد لا يعمل التطبيق بالشكل الأمثل";
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF7F8FC),
|
||||
appBar: AppBar(
|
||||
title: const Text("توافق الجهاز",
|
||||
style:
|
||||
TextStyle(color: Colors.black87, fontWeight: FontWeight.bold)),
|
||||
centerTitle: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
iconTheme: const IconThemeData(color: Colors.black87),
|
||||
),
|
||||
body: isLoading
|
||||
? const Center(child: CircularProgressIndicator(color: Colors.teal))
|
||||
: Column(
|
||||
children: [
|
||||
_buildScoreHeader(),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.only(top: 10, bottom: 20),
|
||||
itemCount: details.length,
|
||||
itemBuilder: (context, i) =>
|
||||
CompatibilityDetailCard(detail: details[i]),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 24),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.teal,
|
||||
minimumSize: const Size(double.infinity, 50),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
elevation: 0,
|
||||
),
|
||||
onPressed: () => Get.back(),
|
||||
child: const Text("المتابعة إلى التطبيق",
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// ## Corrected Score Header Widget
|
||||
/// This widget now uses a `Stack` to correctly place the text over the `PieChart`.
|
||||
Widget _buildScoreHeader() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
height: 220, // Give the container a fixed height
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
// Layer 1: The Pie Chart
|
||||
PieChart(
|
||||
PieChartData(
|
||||
sectionsSpace: 4,
|
||||
// This creates the "hole" in the middle.
|
||||
centerSpaceRadius: 80,
|
||||
startDegreeOffset: -90,
|
||||
sections: [
|
||||
PieChartSectionData(
|
||||
color: _getColorForScore(score),
|
||||
value: score.toDouble(),
|
||||
title: '',
|
||||
radius: 25,
|
||||
),
|
||||
PieChartSectionData(
|
||||
color: Colors.grey.shade200,
|
||||
value: (100 - score).toDouble().clamp(0, 100),
|
||||
title: '',
|
||||
radius: 25,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Layer 2: The text and message, centered on top of the chart
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"$score%",
|
||||
style: TextStyle(
|
||||
fontSize: 52,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _getColorForScore(score)),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
_getScoreMessage(score),
|
||||
style: TextStyle(
|
||||
color: Colors.grey.shade700,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user