2026-03-10-1
This commit is contained in:
@@ -5,7 +5,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:url_launcher/url_launcher.dart'; // ضروري من أجل الاتصال
|
||||
import 'package:sefer_admin1/constant/links.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../../constant/box_name.dart';
|
||||
import '../../../main.dart';
|
||||
@@ -17,7 +18,8 @@ class IntaleqTrackerScreen extends StatefulWidget {
|
||||
State<IntaleqTrackerScreen> createState() => _IntaleqTrackerScreenState();
|
||||
}
|
||||
|
||||
class _IntaleqTrackerScreenState extends State<IntaleqTrackerScreen> {
|
||||
class _IntaleqTrackerScreenState extends State<IntaleqTrackerScreen>
|
||||
with TickerProviderStateMixin {
|
||||
// === Map Controller ===
|
||||
final MapController _mapController = MapController();
|
||||
List<Marker> _markers = [];
|
||||
@@ -32,58 +34,83 @@ class _IntaleqTrackerScreenState extends State<IntaleqTrackerScreen> {
|
||||
int dayCount = 0;
|
||||
Timer? _timer;
|
||||
|
||||
// === Animation Controllers ===
|
||||
late AnimationController _fadeController;
|
||||
late AnimationController _scaleController;
|
||||
|
||||
// === Admin Info ===
|
||||
String myPhone = box.read(BoxName.adminPhone).toString();
|
||||
bool get isSuperAdmin =>
|
||||
myPhone == '963942542053' || myPhone == '963992952235';
|
||||
|
||||
// === URLs ===
|
||||
final String _baseDir = "https://api.intaleq.xyz/intaleq/ride/location/";
|
||||
final String _baseDir = "${AppLink.server}/ride/location/";
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initAnimations();
|
||||
fetchData();
|
||||
|
||||
// === تعديل 1: التحديث كل 5 دقائق بدلاً من 15 ثانية ===
|
||||
_timer = Timer.periodic(const Duration(minutes: 5), (timer) {
|
||||
if (mounted) fetchData();
|
||||
});
|
||||
}
|
||||
|
||||
void _initAnimations() {
|
||||
_fadeController = AnimationController(
|
||||
duration: const Duration(milliseconds: 800),
|
||||
vsync: this,
|
||||
);
|
||||
_scaleController = AnimationController(
|
||||
duration: const Duration(milliseconds: 600),
|
||||
vsync: this,
|
||||
);
|
||||
_fadeController.forward();
|
||||
_scaleController.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
_mapController.dispose();
|
||||
_fadeController.dispose();
|
||||
_scaleController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// === دالة إجراء الاتصال ===
|
||||
Future<void> _makePhoneCall(String phoneNumber) async {
|
||||
final Uri launchUri = Uri(scheme: 'tel', path: phoneNumber);
|
||||
if (await canLaunchUrl(launchUri)) {
|
||||
await launchUrl(launchUri);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("لا يمكن إجراء الاتصال لهذا الرقم")),
|
||||
);
|
||||
_showSnackBar("لا يمكن إجراء الاتصال لهذا الرقم");
|
||||
}
|
||||
}
|
||||
|
||||
// === Fetch Data Function ===
|
||||
void _showSnackBar(String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
backgroundColor: const Color(0xFF2C3E50),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
margin: const EdgeInsets.all(16),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> fetchData() async {
|
||||
if (!mounted) return;
|
||||
setState(() => isLoading = true);
|
||||
|
||||
try {
|
||||
// 1. طلب التحديث من PHP
|
||||
String updateUrl =
|
||||
"${_baseDir}getUpdatedLocationForAdmin.php?mode=${isLiveMode ? 'live' : 'day'}";
|
||||
await http.get(Uri.parse(updateUrl));
|
||||
|
||||
String v = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
|
||||
// === Live Data ===
|
||||
final responseLive =
|
||||
await http.get(Uri.parse("${_baseDir}locations_live.json?v=$v"));
|
||||
if (responseLive.statusCode == 200) {
|
||||
@@ -98,7 +125,6 @@ class _IntaleqTrackerScreenState extends State<IntaleqTrackerScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
// === Day Data ===
|
||||
final responseDay =
|
||||
await http.get(Uri.parse("${_baseDir}locations_day.json?v=$v"));
|
||||
if (responseDay.statusCode == 200) {
|
||||
@@ -124,7 +150,6 @@ class _IntaleqTrackerScreenState extends State<IntaleqTrackerScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// === Build Markers ===
|
||||
void _buildMarkers(List<dynamic> drivers) {
|
||||
List<Marker> newMarkers = [];
|
||||
|
||||
@@ -144,8 +169,8 @@ class _IntaleqTrackerScreenState extends State<IntaleqTrackerScreen> {
|
||||
newMarkers.add(
|
||||
Marker(
|
||||
point: LatLng(lat, lon),
|
||||
width: 50,
|
||||
height: 50,
|
||||
width: 60,
|
||||
height: 60,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
_showDriverInfoDialog(
|
||||
@@ -158,31 +183,7 @@ class _IntaleqTrackerScreenState extends State<IntaleqTrackerScreen> {
|
||||
cancelled: cancelled,
|
||||
);
|
||||
},
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.9),
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: const [
|
||||
BoxShadow(blurRadius: 3, color: Colors.black26)
|
||||
]),
|
||||
),
|
||||
Transform.rotate(
|
||||
angle: heading * (math.pi / 180),
|
||||
child: Icon(
|
||||
Icons.navigation,
|
||||
color: isLiveMode
|
||||
? const Color(0xFF27AE60)
|
||||
: const Color(0xFF2980B9),
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: _buildMarkerWidget(heading),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -193,7 +194,46 @@ class _IntaleqTrackerScreenState extends State<IntaleqTrackerScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
// === Dialog Function ===
|
||||
Widget _buildMarkerWidget(double heading) {
|
||||
return Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: isLiveMode
|
||||
? [const Color(0xFF27AE60), const Color(0xFF229954)]
|
||||
: [const Color(0xFF3498DB), const Color(0xFF2980B9)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: (isLiveMode
|
||||
? const Color(0xFF27AE60)
|
||||
: const Color(0xFF3498DB))
|
||||
.withOpacity(0.5),
|
||||
blurRadius: 12,
|
||||
spreadRadius: 2,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Transform.rotate(
|
||||
angle: heading * (math.pi / 180),
|
||||
child: Icon(
|
||||
Icons.navigation,
|
||||
color: Colors.white,
|
||||
size: 26,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _showDriverInfoDialog({
|
||||
required String driverId,
|
||||
required String name,
|
||||
@@ -206,243 +246,583 @@ class _IntaleqTrackerScreenState extends State<IntaleqTrackerScreen> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
backgroundColor: Colors.white,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text("بيانات الكابتن",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF2C3E50))),
|
||||
const Divider(thickness: 1, height: 25),
|
||||
_infoRow(Icons.person, "الاسم", name),
|
||||
_infoRow(Icons.badge, "المعرف (ID)", driverId),
|
||||
_infoRow(Icons.speed, "السرعة", "$speed كم/س"),
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade50,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.grey.shade200)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_statItem("مكتملة", completed, Colors.green),
|
||||
Container(
|
||||
width: 1, height: 30, color: Colors.grey.shade300),
|
||||
_statItem("ملغاة", cancelled, Colors.red),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// === تعديل 2: جعل رقم الهاتف قابلاً للنقر ===
|
||||
if (isSuperAdmin) ...[
|
||||
const SizedBox(height: 15),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
if (phone.isNotEmpty) _makePhoneCall(phone);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFF3CD),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFFFEEBA))),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _infoRow(Icons.phone, "الهاتف", phone,
|
||||
isPrivate: true)),
|
||||
const SizedBox(width: 5),
|
||||
const Icon(Icons.call, color: Colors.green, size: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF2C3E50),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text("إغلاق"),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
|
||||
backgroundColor: Colors.transparent,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.white, Colors.grey.shade50],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.15),
|
||||
blurRadius: 30,
|
||||
spreadRadius: 5,
|
||||
)
|
||||
],
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: isLiveMode
|
||||
? [const Color(0xFF27AE60), const Color(0xFF229954)]
|
||||
: [const Color(0xFF3498DB), const Color(0xFF2980B9)],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.person_outline, color: Colors.white, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
"معلومات الكابتن",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildInfoCard(Icons.person, "الاسم", name),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoCard(Icons.badge, "المعرف", driverId),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoCard(Icons.speed, "السرعة", "$speed كم/س"),
|
||||
const SizedBox(height: 20),
|
||||
_buildStatsContainer(completed, cancelled),
|
||||
if (isSuperAdmin) ...[
|
||||
const SizedBox(height: 16),
|
||||
_buildPhoneButton(phone),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF2C3E50),
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
elevation: 0,
|
||||
),
|
||||
child: const Text(
|
||||
"إغلاق",
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Helper Widgets
|
||||
Widget _infoRow(IconData icon, String label, String value,
|
||||
{bool isPrivate = false}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
Widget _buildInfoCard(IconData icon, String label, String value) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade200,
|
||||
width: 1,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 8,
|
||||
)
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon,
|
||||
size: 20,
|
||||
color: isPrivate ? Colors.orange[800] : Colors.grey[600]),
|
||||
const SizedBox(width: 8),
|
||||
Text("$label: ",
|
||||
style:
|
||||
const TextStyle(fontWeight: FontWeight.bold, fontSize: 13)),
|
||||
Expanded(
|
||||
child: Text(value,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight:
|
||||
isPrivate ? FontWeight.bold : FontWeight.normal),
|
||||
textAlign: TextAlign.end)),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(icon, color: const Color(0xFF2C3E50), size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade600,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF2C3E50),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _statItem(String label, String val, Color color) {
|
||||
Widget _buildStatsContainer(String completed, String cancelled) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.grey.shade50, Colors.grey.shade100],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
_buildStatItem("✓ مكتملة", completed, const Color(0xFF27AE60)),
|
||||
Container(
|
||||
width: 1,
|
||||
height: 40,
|
||||
color: Colors.grey.shade300,
|
||||
),
|
||||
_buildStatItem("✕ ملغاة", cancelled, const Color(0xFFE74C3C)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatItem(String label, String value, Color color) {
|
||||
return Column(
|
||||
children: [
|
||||
Text(val,
|
||||
style: TextStyle(
|
||||
color: color, fontWeight: FontWeight.bold, fontSize: 16)),
|
||||
Text(label, style: const TextStyle(fontSize: 11, color: Colors.grey)),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade600,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPhoneButton(String phone) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
if (phone.isNotEmpty) _makePhoneCall(phone);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 14),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [const Color(0xFFFFA500), const Color(0xFFFF8C00)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0xFFFFA500).withOpacity(0.4),
|
||||
blurRadius: 12,
|
||||
spreadRadius: 2,
|
||||
)
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.call, color: Colors.white, size: 20),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
phone,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: AppBar(
|
||||
title: const Text("نظام تتبع الكباتن"),
|
||||
backgroundColor: const Color(0xFF2C3E50),
|
||||
foregroundColor: Colors.white),
|
||||
elevation: 0,
|
||||
backgroundColor: Colors.transparent,
|
||||
centerTitle: true,
|
||||
title: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF2C3E50).withOpacity(0.9),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
// backdropFilter: const BackdropFilter(blur: 10),
|
||||
),
|
||||
child: const Text(
|
||||
"نظام تتبع الكابتن",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
FlutterMap(
|
||||
mapController: _mapController,
|
||||
options: const MapOptions(
|
||||
initialCenter: LatLng(33.513, 36.276), initialZoom: 10.0),
|
||||
initialCenter: LatLng(33.513, 36.276),
|
||||
initialZoom: 10.0,
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
userAgentPackageName: 'com.tripz.app'),
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
userAgentPackageName: 'com.tripz.app',
|
||||
),
|
||||
MarkerLayer(markers: _markers),
|
||||
],
|
||||
),
|
||||
|
||||
// === Dashboard ===
|
||||
Positioned(
|
||||
top: 20,
|
||||
right: 15,
|
||||
child: Container(
|
||||
width: 260,
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.95),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [
|
||||
BoxShadow(color: Colors.black12, blurRadius: 10)
|
||||
]),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
const Text("لوحة التحكم",
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
const Divider(),
|
||||
|
||||
// أزرار التبديل
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _modeBtn("أرشيف اليوم", !isLiveMode, () {
|
||||
setState(() => isLiveMode = false);
|
||||
fetchData();
|
||||
})),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _modeBtn("مباشر", isLiveMode, () {
|
||||
setState(() => isLiveMode = true);
|
||||
fetchData();
|
||||
})),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
// === عرض العدادين معاً ===
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text("$liveCount",
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF27AE60),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14)),
|
||||
const Text("نشط الآن (مباشر):",
|
||||
style: TextStyle(fontSize: 12)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text("$dayCount",
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF2980B9),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14)),
|
||||
const Text("إجمالي اليوم:",
|
||||
style: TextStyle(fontSize: 12)),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 10),
|
||||
Text(isLoading ? "جاري التحديث..." : "تحديث: $lastUpdated",
|
||||
style: const TextStyle(fontSize: 10, color: Colors.grey)),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: isLoading ? null : fetchData,
|
||||
child: const Text("تحديث البيانات")))
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildDashboard(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _modeBtn(String title, bool active, VoidCallback onTap) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: active ? const Color(0xFF3498DB) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(color: const Color(0xFF3498DB))),
|
||||
child: Text(title,
|
||||
style: TextStyle(
|
||||
color: active ? Colors.white : const Color(0xFF3498DB),
|
||||
fontWeight: active ? FontWeight.bold : FontWeight.normal)),
|
||||
Widget _buildDashboard() {
|
||||
return Positioned(
|
||||
top: 100,
|
||||
right: 16,
|
||||
child: FadeTransition(
|
||||
opacity: _fadeController,
|
||||
child: ScaleTransition(
|
||||
scale: _scaleController,
|
||||
child: Container(
|
||||
width: 300,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.15),
|
||||
blurRadius: 30,
|
||||
spreadRadius: 5,
|
||||
)
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
const Color(0xFF2C3E50),
|
||||
const Color(0xFF34495E)
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Icon(Icons.dashboard,
|
||||
color: Colors.white, size: 22),
|
||||
const Text(
|
||||
"لوحة التحكم",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
// Mode Buttons
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildModeButton(
|
||||
"أرشيف اليوم",
|
||||
!isLiveMode,
|
||||
() {
|
||||
setState(() => isLiveMode = false);
|
||||
fetchData();
|
||||
},
|
||||
const Color(0xFF3498DB),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: _buildModeButton(
|
||||
"مباشر",
|
||||
isLiveMode,
|
||||
() {
|
||||
setState(() => isLiveMode = true);
|
||||
fetchData();
|
||||
},
|
||||
const Color(0xFF27AE60),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Stats
|
||||
_buildStatRow(
|
||||
icon: Icons.live_tv,
|
||||
label: "نشط الآن (مباشر)",
|
||||
value: liveCount.toString(),
|
||||
color: const Color(0xFF27AE60),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildStatRow(
|
||||
icon: Icons.history,
|
||||
label: "إجمالي اليوم",
|
||||
value: dayCount.toString(),
|
||||
color: const Color(0xFF3498DB),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// Last Update
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade50,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
isLoading
|
||||
? "جاري التحديث..."
|
||||
: "تحديث: $lastUpdated",
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: Colors.grey.shade600,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
isLoading
|
||||
? Icons.hourglass_bottom
|
||||
: Icons.check_circle,
|
||||
size: 14,
|
||||
color: isLoading ? Colors.orange : Colors.green,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Refresh Button
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: isLoading ? null : fetchData,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF2C3E50),
|
||||
foregroundColor: Colors.white,
|
||||
disabledBackgroundColor: Colors.grey.shade300,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
elevation: 0,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (isLoading)
|
||||
const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Colors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
const Icon(Icons.refresh, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
"تحديث البيانات",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildModeButton(
|
||||
String title,
|
||||
bool active,
|
||||
VoidCallback onTap,
|
||||
Color color,
|
||||
) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
gradient: active
|
||||
? LinearGradient(
|
||||
colors: [color, color.withOpacity(0.8)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
)
|
||||
: null,
|
||||
color: active ? null : Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: active ? color : Colors.grey.shade300,
|
||||
width: 1.5,
|
||||
),
|
||||
boxShadow: active
|
||||
? [
|
||||
BoxShadow(
|
||||
color: color.withOpacity(0.3),
|
||||
blurRadius: 8,
|
||||
spreadRadius: 1,
|
||||
)
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
color: active ? Colors.white : Colors.grey.shade700,
|
||||
fontWeight: active ? FontWeight.bold : FontWeight.w600,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatRow({
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required String value,
|
||||
required Color color,
|
||||
}) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(icon, color: color, size: 18),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade600,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user