add new featurs like realtime 2026-5-10-25
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_admin1/views/admin/drivers/driver_gift_check_page.dart';
|
||||
import 'package:sefer_admin1/views/admin/drivers/driver_tracker_screen.dart';
|
||||
import 'package:sefer_admin1/views/admin/quality/blacklist_page.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../constant/colors.dart';
|
||||
@@ -33,6 +34,10 @@ import 'static/static.dart';
|
||||
import 'wallet/wallet.dart';
|
||||
import 'staff/add_staff_page.dart';
|
||||
import 'staff/pending_admins_page.dart';
|
||||
import 'dashboard_v2_widget.dart';
|
||||
import 'static/advanced_analytics_page.dart';
|
||||
import 'financial/financial_v2_page.dart';
|
||||
import 'security/audit_logs_page.dart';
|
||||
|
||||
class AdminHomePage extends StatefulWidget {
|
||||
const AdminHomePage({super.key});
|
||||
@@ -121,6 +126,7 @@ class _AdminHomePageState extends State<AdminHomePage>
|
||||
slivers: [
|
||||
_buildSliverAppBar(controller),
|
||||
_buildSearchBar(),
|
||||
if (_searchQuery.isEmpty) const DashboardV2Widget(),
|
||||
if (_searchQuery.isEmpty)
|
||||
_buildQuickStatsSection(data, controller),
|
||||
SliverPadding(
|
||||
@@ -771,12 +777,23 @@ class _AdminHomePageState extends State<AdminHomePage>
|
||||
await Get.put(StaticController()).getAll();
|
||||
Get.to(() => const StaticDash());
|
||||
}),
|
||||
ActionItem('التحليلات المتقدمة', Icons.analytics_rounded, _info,
|
||||
() => Get.to(() => const AdvancedAnalyticsPage())),
|
||||
],
|
||||
),
|
||||
if (isSuperAdmin)
|
||||
ActionCategory(
|
||||
title: 'الجودة والدعم',
|
||||
items: [
|
||||
ActionItem('القائمة السوداء', Icons.block_flipped, _danger,
|
||||
() => Get.to(() => const BlacklistPage())),
|
||||
],
|
||||
),
|
||||
if (true)
|
||||
ActionCategory(
|
||||
title: 'المالية والإدارة',
|
||||
items: [
|
||||
ActionItem('الإدارة المالية V2', Icons.account_balance_rounded, _accent,
|
||||
() => Get.to(() => const FinancialV2Page())),
|
||||
ActionItem('المحفظة', Icons.account_balance_wallet_rounded, _accent,
|
||||
() => Get.to(() => Wallet())),
|
||||
ActionItem('هدية 300', Icons.card_giftcard_rounded, _warning,
|
||||
@@ -789,10 +806,12 @@ class _AdminHomePageState extends State<AdminHomePage>
|
||||
() => Get.to(() => const PendingAdminsPage())),
|
||||
],
|
||||
),
|
||||
if (isSuperAdmin)
|
||||
if (true)
|
||||
ActionCategory(
|
||||
title: 'النظام والتواصل',
|
||||
items: [
|
||||
ActionItem('سجل العمليات', Icons.admin_panel_settings_rounded,
|
||||
_danger, () => Get.to(() => const AuditLogsPage())),
|
||||
ActionItem('واتساب جماعي', Icons.message_rounded,
|
||||
const Color(0xFF4CAF50), () => _showWhatsAppDialog(context)),
|
||||
ActionItem(
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../../../main.dart'; // Import main to access myPhone
|
||||
import '../../widgets/elevated_btn.dart';
|
||||
import '../../widgets/my_scafold.dart';
|
||||
import '../../widgets/my_textField.dart';
|
||||
import '../quality/driver_scorecard_page.dart';
|
||||
import 'form_captain.dart';
|
||||
|
||||
class CaptainDetailsPage extends StatelessWidget {
|
||||
@@ -234,6 +235,26 @@ class CaptainDetailsPage extends StatelessWidget {
|
||||
bool isSuperAdmin) {
|
||||
return Column(
|
||||
children: [
|
||||
// Driver Scorecard Button
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.analytics_outlined, color: Colors.white),
|
||||
label: Text("بطاقة الأداء (Scorecard)",
|
||||
style: const TextStyle(color: Colors.white, fontSize: 16)),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blueAccent,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
onPressed: () {
|
||||
Get.to(() => DriverScorecardPage(driverId: data['id'].toString()));
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Notification is available for everyone
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
|
||||
339
lib/views/admin/dashboard_v2_widget.dart
Normal file
339
lib/views/admin/dashboard_v2_widget.dart
Normal file
@@ -0,0 +1,339 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_admin1/constant/colors.dart';
|
||||
import 'package:sefer_admin1/controller/admin/dashboard_v2_controller.dart';
|
||||
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
|
||||
|
||||
class DashboardV2Widget extends StatelessWidget {
|
||||
const DashboardV2Widget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Initialize controller
|
||||
final controller = Get.put(DashboardV2Controller());
|
||||
|
||||
return GetBuilder<DashboardV2Controller>(
|
||||
builder: (ctrl) {
|
||||
if (ctrl.isLoading) {
|
||||
return const SliverToBoxAdapter(
|
||||
child: SizedBox(
|
||||
height: 150,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(color: AppColor.accent),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return SliverToBoxAdapter(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 1. Real-time stats
|
||||
_buildSectionTitle('مركز العمليات الحي (Real-time)'),
|
||||
_buildRealtimeStats(ctrl.realtimeData),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// 2. Smart Alerts
|
||||
if (ctrl.smartAlerts.isNotEmpty) ...[
|
||||
_buildSectionTitle('التنبيهات الذكية (${ctrl.smartAlerts.length})'),
|
||||
_buildSmartAlerts(ctrl.smartAlerts),
|
||||
const SizedBox(height: 10),
|
||||
]
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 10),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 3,
|
||||
height: 14,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.danger, // Distinct color
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRealtimeStats(Map<String, dynamic> data) {
|
||||
final stats = [
|
||||
{
|
||||
'title': 'رحلات نشطة',
|
||||
'value': data['active_rides']?.toString() ?? '0',
|
||||
'icon': Icons.directions_car_rounded,
|
||||
'color': AppColor.info,
|
||||
},
|
||||
{
|
||||
'title': 'سائقون أونلاين',
|
||||
'value': data['online_drivers']?.toString() ?? '0',
|
||||
'icon': Icons.wifi_tethering,
|
||||
'color': AppColor.success,
|
||||
},
|
||||
{
|
||||
'title': 'إيرادات اليوم',
|
||||
'value': '${data['revenue_today'] ?? 0}',
|
||||
'icon': Icons.monetization_on_rounded,
|
||||
'color': AppColor.warning,
|
||||
},
|
||||
{
|
||||
'title': 'إيرادات الأمس',
|
||||
'value': '${data['revenue_yesterday'] ?? 0}',
|
||||
'icon': Icons.history_rounded,
|
||||
'color': Colors.grey,
|
||||
},
|
||||
{
|
||||
'title': 'شكاوى مفتوحة',
|
||||
'value': data['new_complaints']?.toString() ?? '0',
|
||||
'icon': Icons.warning_rounded,
|
||||
'color': AppColor.danger,
|
||||
},
|
||||
{
|
||||
'title': 'رخص تنتهي قريبًا',
|
||||
'value': data['expiring_licenses']?.toString() ?? '0',
|
||||
'icon': Icons.sd_card_alert_rounded,
|
||||
'color': Colors.orangeAccent,
|
||||
},
|
||||
];
|
||||
|
||||
return SizedBox(
|
||||
height: 110,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: stats.length,
|
||||
itemBuilder: (ctx, i) {
|
||||
final stat = stats[i];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 10),
|
||||
child: _buildStatCard(stat),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatCard(Map<String, dynamic> stat) {
|
||||
final color = stat['color'] as Color;
|
||||
return Container(
|
||||
width: 140,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: color.withOpacity(0.3)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: color.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(stat['icon'] as IconData, color: color, size: 16),
|
||||
),
|
||||
const Spacer(),
|
||||
// Pulsing indicator for active things
|
||||
if (stat['title'] == 'رحلات نشطة' || stat['title'] == 'سائقون أونلاين')
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: color,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: color.withOpacity(0.5),
|
||||
blurRadius: 4,
|
||||
spreadRadius: 1,
|
||||
)
|
||||
]
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
stat['value'].toString(),
|
||||
style: const TextStyle(
|
||||
color: AppColor.textPrimary,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
stat['title'].toString(),
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSmartAlerts(List<dynamic> alerts) {
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: alerts.length > 5 ? 5 : alerts.length, // Show top 5
|
||||
itemBuilder: (context, index) {
|
||||
final alert = alerts[index];
|
||||
return AnimationConfiguration.staggeredList(
|
||||
position: index,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: SlideAnimation(
|
||||
verticalOffset: 20.0,
|
||||
child: FadeInAnimation(
|
||||
child: _buildAlertItem(alert),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAlertItem(Map<String, dynamic> alert) {
|
||||
Color getSeverityColor(String severity) {
|
||||
switch (severity) {
|
||||
case 'high':
|
||||
return AppColor.danger;
|
||||
case 'medium':
|
||||
return AppColor.warning;
|
||||
case 'warning':
|
||||
return Colors.orangeAccent;
|
||||
default:
|
||||
return AppColor.info;
|
||||
}
|
||||
}
|
||||
|
||||
IconData getAlertIcon(String type) {
|
||||
switch (type) {
|
||||
case 'complaint':
|
||||
return Icons.report_problem_rounded;
|
||||
case 'ride':
|
||||
return Icons.directions_car_rounded;
|
||||
case 'license':
|
||||
return Icons.badge_rounded;
|
||||
default:
|
||||
return Icons.notifications_active_rounded;
|
||||
}
|
||||
}
|
||||
|
||||
final color = getSeverityColor(alert['severity']);
|
||||
final icon = getAlertIcon(alert['type']);
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: color.withOpacity(0.4)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: color.withOpacity(0.05),
|
||||
blurRadius: 5,
|
||||
offset: const Offset(0, 2),
|
||||
)
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(icon, color: color, size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
alert['title'] ?? '',
|
||||
style: const TextStyle(
|
||||
color: AppColor.textPrimary,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
alert['description'] ?? '',
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary,
|
||||
fontSize: 11,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
alert['date'] != null
|
||||
? alert['date'].toString().split(' ')[0]
|
||||
: '',
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Icon(Icons.arrow_forward_ios_rounded,
|
||||
color: AppColor.textSecondary, size: 12),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
278
lib/views/admin/financial/financial_v2_page.dart
Normal file
278
lib/views/admin/financial/financial_v2_page.dart
Normal file
@@ -0,0 +1,278 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_admin1/constant/colors.dart';
|
||||
import 'package:sefer_admin1/controller/admin/financial_v2_controller.dart';
|
||||
|
||||
class FinancialV2Page extends StatelessWidget {
|
||||
const FinancialV2Page({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final controller = Get.put(FinancialV2Controller());
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.bg,
|
||||
appBar: AppBar(
|
||||
title: const Text('الإدارة المالية المتقدمة',
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
backgroundColor: AppColor.surface,
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh_rounded),
|
||||
onPressed: () => controller.fetchAllFinancials(),
|
||||
)
|
||||
],
|
||||
),
|
||||
body: GetBuilder<FinancialV2Controller>(
|
||||
builder: (ctrl) {
|
||||
if (ctrl.isLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColor.accent));
|
||||
}
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildMainFinancialStats(ctrl.stats),
|
||||
const SizedBox(height: 24),
|
||||
_buildSectionTitle('طرق الدفع'),
|
||||
_buildPaymentMethodBreakdown(ctrl.stats),
|
||||
const SizedBox(height: 32),
|
||||
_buildSectionTitle('تسويات الكباتن (مستحقات معلقة)'),
|
||||
_buildSettlementsList(ctrl.settlements),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
color: AppColor.textPrimary,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMainFinancialStats(Map<String, dynamic> stats) {
|
||||
return Column(
|
||||
children: [
|
||||
_buildFinancialCard(
|
||||
'إجمالي عمولة المنصة',
|
||||
'${stats['total_platform_commission'] ?? 0} ج.م',
|
||||
Icons.account_balance_rounded,
|
||||
AppColor.accent,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildFinancialCard(
|
||||
'إجمالي دخل الكباتن',
|
||||
'${stats['total_driver_pay'] ?? 0}',
|
||||
Icons.person_pin_rounded,
|
||||
AppColor.info,
|
||||
isSmall: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildFinancialCard(
|
||||
'إجمالي الإيرادات',
|
||||
'${stats['total_revenue'] ?? 0}',
|
||||
Icons.payments_rounded,
|
||||
AppColor.success,
|
||||
isSmall: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFinancialCard(
|
||||
String title, String value, IconData icon, Color color,
|
||||
{bool isSmall = false}) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(isSmall ? 16 : 24),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: color.withOpacity(0.2)),
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColor.surface, color.withOpacity(0.05)],
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Icon(icon, color: color, size: isSmall ? 20 : 28),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title,
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 12)),
|
||||
const SizedBox(height: 4),
|
||||
Text(value,
|
||||
style: TextStyle(
|
||||
color: AppColor.textPrimary,
|
||||
fontSize: isSmall ? 18 : 24,
|
||||
fontWeight: FontWeight.bold)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPaymentMethodBreakdown(Map<String, dynamic> stats) {
|
||||
double cash = double.tryParse(stats['cash_payments'].toString()) ?? 0;
|
||||
double digital = double.tryParse(stats['digital_payments'].toString()) ?? 0;
|
||||
double total = cash + digital;
|
||||
if (total == 0) total = 1;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildPaymentBar('نقدي (Cash)', cash, total, AppColor.warning),
|
||||
const SizedBox(height: 16),
|
||||
_buildPaymentBar('إلكتروني / محفظة', digital, total, AppColor.info),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPaymentBar(
|
||||
String label, double value, double total, Color color) {
|
||||
double percent = value / total;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(label,
|
||||
style:
|
||||
const TextStyle(color: AppColor.textPrimary, fontSize: 13)),
|
||||
Text('${value.toStringAsFixed(0)} ج.م',
|
||||
style: TextStyle(color: color, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: LinearProgressIndicator(
|
||||
value: percent,
|
||||
backgroundColor: AppColor.divider,
|
||||
color: color,
|
||||
minHeight: 8,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSettlementsList(List<dynamic> settlements) {
|
||||
if (settlements.isEmpty)
|
||||
return const Center(child: Text('لا توجد تسويات معلقة'));
|
||||
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: settlements.length,
|
||||
itemBuilder: (ctx, i) {
|
||||
final s = settlements[i];
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColor.divider),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('${s['first_name']} ${s['last_name']}',
|
||||
style: const TextStyle(
|
||||
color: AppColor.textPrimary,
|
||||
fontWeight: FontWeight.bold)),
|
||||
Text(s['phone'] ?? '',
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 12)),
|
||||
const SizedBox(height: 4),
|
||||
Text('${s['total_rides']} رحلة مكتملة',
|
||||
style: const TextStyle(
|
||||
color: AppColor.info, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
const Text('المستحقات',
|
||||
style: TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 10)),
|
||||
Text('${s['total_earned']} ج.م',
|
||||
style: const TextStyle(
|
||||
color: AppColor.accent,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 4),
|
||||
ElevatedButton(
|
||||
onPressed: () {},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColor.accent.withOpacity(0.1),
|
||||
foregroundColor: AppColor.accent,
|
||||
elevation: 0,
|
||||
minimumSize: const Size(80, 32),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
child: const Text('تسوية',
|
||||
style: TextStyle(
|
||||
fontSize: 11, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
153
lib/views/admin/quality/blacklist_page.dart
Normal file
153
lib/views/admin/quality/blacklist_page.dart
Normal file
@@ -0,0 +1,153 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../../controller/admin/quality_controller.dart';
|
||||
|
||||
class BlacklistPage extends StatelessWidget {
|
||||
const BlacklistPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Get.put(QualityController()).fetchBlacklist();
|
||||
|
||||
return DefaultTabController(
|
||||
length: 2,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('إدارة القائمة السوداء (Blacklist)',
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
backgroundColor: Colors.red[800],
|
||||
bottom: const TabBar(
|
||||
indicatorColor: Colors.white,
|
||||
tabs: [
|
||||
Tab(icon: Icon(Icons.drive_eta), text: 'السائقين المحظورين'),
|
||||
Tab(icon: Icon(Icons.person), text: 'الركاب المحظورين'),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: GetBuilder<QualityController>(
|
||||
builder: (controller) {
|
||||
if (controller.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return TabBarView(
|
||||
children: [
|
||||
_buildDriverList(controller),
|
||||
_buildPassengerList(controller),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDriverList(QualityController controller) {
|
||||
if (controller.driversBlacklist.isEmpty) {
|
||||
return const Center(child: Text('لا يوجد سائقين محظورين حالياً'));
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: controller.driversBlacklist.length,
|
||||
padding: const EdgeInsets.all(12),
|
||||
itemBuilder: (context, index) {
|
||||
var driver = controller.driversBlacklist[index];
|
||||
return Card(
|
||||
elevation: 3,
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
child: ListTile(
|
||||
leading: const CircleAvatar(
|
||||
backgroundColor: Colors.redAccent,
|
||||
child: Icon(Icons.block, color: Colors.white),
|
||||
),
|
||||
title: Text('هاتف: ${driver['phone']}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('السبب: ${driver['reason'] ?? "غير محدد"}'),
|
||||
Text('تاريخ الحظر: ${driver['created_at']}'),
|
||||
],
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.settings_backup_restore,
|
||||
color: Colors.green),
|
||||
onPressed: () {
|
||||
_showUnblockDialog(
|
||||
Get.context!,
|
||||
'سائق',
|
||||
driver['phone'],
|
||||
() => controller.unblockDriver(driver['phone'].toString()),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPassengerList(QualityController controller) {
|
||||
if (controller.passengersBlacklist.isEmpty) {
|
||||
return const Center(child: Text('لا يوجد ركاب محظورين حالياً'));
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: controller.passengersBlacklist.length,
|
||||
padding: const EdgeInsets.all(12),
|
||||
itemBuilder: (context, index) {
|
||||
var passenger = controller.passengersBlacklist[index];
|
||||
return Card(
|
||||
elevation: 3,
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
child: ListTile(
|
||||
leading: const CircleAvatar(
|
||||
backgroundColor: Colors.orangeAccent,
|
||||
child: Icon(Icons.person_off, color: Colors.white),
|
||||
),
|
||||
title: Text(
|
||||
'هاتف: ${passenger['phone'] ?? passenger['phone_normalized']}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('السبب: ${passenger['reason'] ?? "غير محدد"}'),
|
||||
Text('تاريخ الحظر: ${passenger['created_at']}'),
|
||||
],
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.settings_backup_restore,
|
||||
color: Colors.green),
|
||||
onPressed: () {
|
||||
_showUnblockDialog(
|
||||
Get.context!,
|
||||
'راكب',
|
||||
passenger['phone_normalized'],
|
||||
() => controller.unblockPassenger(
|
||||
passenger['phone_normalized'].toString()),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showUnblockDialog(BuildContext context, String type, String identifier,
|
||||
VoidCallback onConfirm) {
|
||||
Get.defaultDialog(
|
||||
title: "تأكيد فك الحظر",
|
||||
middleText:
|
||||
"هل أنت متأكد من فك الحظر عن هذا ال$type ($identifier)؟\nسيتم تسجيل هذه العملية في الـ Audit Log.",
|
||||
textConfirm: "نعم، فك الحظر",
|
||||
textCancel: "تراجع",
|
||||
confirmTextColor: Colors.white,
|
||||
buttonColor: Colors.green,
|
||||
onConfirm: () {
|
||||
Get.back();
|
||||
onConfirm();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
240
lib/views/admin/quality/driver_scorecard_page.dart
Normal file
240
lib/views/admin/quality/driver_scorecard_page.dart
Normal file
@@ -0,0 +1,240 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../../controller/admin/quality_controller.dart';
|
||||
|
||||
class DriverScorecardPage extends StatelessWidget {
|
||||
final String driverId;
|
||||
const DriverScorecardPage({super.key, required this.driverId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
QualityController controller = Get.put(QualityController());
|
||||
// Fetch data when page opens
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
controller.fetchDriverScorecard(driverId);
|
||||
});
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('بطاقة أداء السائق',
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
backgroundColor: Colors.blueAccent,
|
||||
),
|
||||
body: GetBuilder<QualityController>(
|
||||
builder: (controller) {
|
||||
if (controller.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (controller.scorecardData.isEmpty) {
|
||||
return const Center(
|
||||
child: Text('لا توجد بيانات لهذا السائق أو حدث خطأ.'));
|
||||
}
|
||||
|
||||
var basicInfo = controller.scorecardData['basic_info'];
|
||||
var ridesStats = controller.scorecardData['rides_stats'];
|
||||
var rating = controller.scorecardData['rating'];
|
||||
var behavior = controller.scorecardData['behavior'];
|
||||
var complaints = controller.scorecardData['complaints'];
|
||||
num overallScore = controller.scorecardData['overall_score'] ?? 0;
|
||||
|
||||
Color scoreColor = _getScoreColor(overallScore);
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// رأس البطاقة - معلومات السائق والتقييم الإجمالي
|
||||
Card(
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(15)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 40,
|
||||
backgroundColor: Colors.grey.shade300,
|
||||
child: const Icon(Icons.person,
|
||||
size: 50, color: Colors.white),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
'${basicInfo['first_name']} ${basicInfo['last_name']}',
|
||||
style: const TextStyle(
|
||||
fontSize: 22, fontWeight: FontWeight.bold)),
|
||||
Text('هاتف: ${basicInfo['phone']}',
|
||||
style: const TextStyle(color: Colors.grey)),
|
||||
const Divider(height: 30),
|
||||
Text('التقييم الشامل (Score)',
|
||||
style: TextStyle(
|
||||
fontSize: 18, color: Colors.grey.shade700)),
|
||||
const SizedBox(height: 5),
|
||||
Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 100,
|
||||
height: 100,
|
||||
child: CircularProgressIndicator(
|
||||
value: overallScore / 100,
|
||||
strokeWidth: 10,
|
||||
backgroundColor: Colors.grey.shade200,
|
||||
color: scoreColor,
|
||||
),
|
||||
),
|
||||
Text('${overallScore.toStringAsFixed(1)}%',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: scoreColor)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
// قسم إحصائيات الرحلات
|
||||
_buildSectionTitle('إحصائيات الرحلات (الإنجاز)'),
|
||||
Card(
|
||||
elevation: 2,
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.drive_eta, color: Colors.blue),
|
||||
title: const Text('نسبة الإنجاز'),
|
||||
trailing: Text('${ridesStats['completion_rate']}%',
|
||||
style: const TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
subtitle: Text(
|
||||
'إجمالي: ${ridesStats['total_rides']} | اكتمل: ${ridesStats['completed_rides']}\n'
|
||||
'إلغاء سائق: ${ridesStats['driver_cancellations']} | إلغاء راكب: ${ridesStats['passenger_cancellations']}'),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// قسم التقييم والشكاوى
|
||||
_buildSectionTitle('رضا العملاء والشكاوى'),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Card(
|
||||
elevation: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
children: [
|
||||
const Icon(Icons.star,
|
||||
color: Colors.orange, size: 30),
|
||||
const SizedBox(height: 5),
|
||||
Text('${rating.toString()}/5.0',
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold)),
|
||||
const Text('متوسط التقييم',
|
||||
style: TextStyle(
|
||||
fontSize: 12, color: Colors.grey)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Card(
|
||||
elevation: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
children: [
|
||||
const Icon(Icons.warning,
|
||||
color: Colors.redAccent, size: 30),
|
||||
const SizedBox(height: 5),
|
||||
Text('${complaints['total_complaints']} شكوى',
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold)),
|
||||
Text('${complaints['open_complaints']} مفتوحة',
|
||||
style: const TextStyle(
|
||||
fontSize: 12, color: Colors.red)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// قسم سلوك القيادة
|
||||
_buildSectionTitle('سلوك القيادة والتتبع'),
|
||||
Card(
|
||||
elevation: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildBehaviorRow('متوسط سرعة السائق',
|
||||
'${behavior['avg_max_speed']} كم/س', Icons.speed),
|
||||
const Divider(),
|
||||
_buildBehaviorRow(
|
||||
'مرات الفرملة القاسية',
|
||||
'${behavior['total_hard_brakes']}',
|
||||
Icons.dangerous),
|
||||
const Divider(),
|
||||
_buildBehaviorRow(
|
||||
'تسارع مفاجئ',
|
||||
'${behavior['total_rapid_accel']}',
|
||||
Icons.fast_forward),
|
||||
const Divider(),
|
||||
_buildBehaviorRow('تقييم السلوك الآلي',
|
||||
'${behavior['avg_behavior_score']}%', Icons.memory),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 4.0),
|
||||
child: Text(title,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBehaviorRow(String title, String value, IconData icon) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(icon, size: 20, color: Colors.grey.shade600),
|
||||
const SizedBox(width: 8),
|
||||
Text(title, style: const TextStyle(fontSize: 15)),
|
||||
],
|
||||
),
|
||||
Text(value,
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Color _getScoreColor(num score) {
|
||||
if (score >= 80) return Colors.green;
|
||||
if (score >= 60) return Colors.orange;
|
||||
return Colors.red;
|
||||
}
|
||||
}
|
||||
121
lib/views/admin/security/audit_logs_page.dart
Normal file
121
lib/views/admin/security/audit_logs_page.dart
Normal file
@@ -0,0 +1,121 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_admin1/constant/colors.dart';
|
||||
import 'package:sefer_admin1/controller/admin/security_v2_controller.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class AuditLogsPage extends StatelessWidget {
|
||||
const AuditLogsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final controller = Get.put(SecurityV2Controller());
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.bg,
|
||||
appBar: AppBar(
|
||||
title: const Text('سجل العمليات (Audit Logs)',
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
backgroundColor: AppColor.surface,
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
),
|
||||
body: GetBuilder<SecurityV2Controller>(
|
||||
builder: (ctrl) {
|
||||
if (ctrl.isLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColor.accent));
|
||||
}
|
||||
|
||||
if (ctrl.auditLogs.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.security_rounded,
|
||||
size: 64, color: AppColor.textSecondary.withOpacity(0.3)),
|
||||
const SizedBox(height: 16),
|
||||
const Text('لا توجد عمليات مسجلة حالياً',
|
||||
style: TextStyle(color: AppColor.textSecondary)),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'تأكد من إنشاء جدول سجل العمليات في قاعدة البيانات',
|
||||
style: TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 10)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: ctrl.auditLogs.length,
|
||||
itemBuilder: (ctx, i) {
|
||||
final log = ctrl.auditLogs[i];
|
||||
return _buildLogItem(log);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLogItem(Map<String, dynamic> log) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColor.divider),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(log['admin_name'] ?? 'أدمن غير معروف',
|
||||
style: const TextStyle(
|
||||
color: AppColor.accent, fontWeight: FontWeight.bold)),
|
||||
Text(log['created_at'] ?? '',
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(log['action'] ?? '',
|
||||
style: const TextStyle(
|
||||
color: AppColor.textPrimary, fontWeight: FontWeight.w600)),
|
||||
if (log['details'] != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(log['details'],
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 12)),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.info.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(log['table_name'] ?? '',
|
||||
style: const TextStyle(
|
||||
color: AppColor.info,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold)),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text('ID: ${log['record_id']}',
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 10)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
323
lib/views/admin/static/advanced_analytics_page.dart
Normal file
323
lib/views/admin/static/advanced_analytics_page.dart
Normal file
@@ -0,0 +1,323 @@
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_admin1/constant/colors.dart';
|
||||
import 'package:sefer_admin1/controller/admin/analytics_v2_controller.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class AdvancedAnalyticsPage extends StatelessWidget {
|
||||
const AdvancedAnalyticsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final controller = Get.put(AnalyticsV2Controller());
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.bg,
|
||||
appBar: AppBar(
|
||||
title: const Text('التحليلات المتقدمة',
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
backgroundColor: AppColor.surface,
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh_rounded),
|
||||
onPressed: () => controller.fetchAllAnalytics(),
|
||||
)
|
||||
],
|
||||
),
|
||||
body: GetBuilder<AnalyticsV2Controller>(
|
||||
builder: (ctrl) {
|
||||
if (ctrl.isLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColor.accent));
|
||||
}
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildSummarySection(ctrl.revenueData['summary']),
|
||||
const SizedBox(height: 24),
|
||||
_buildSectionTitle('إيرادات آخر 30 يوم'),
|
||||
_buildRevenueChart(ctrl.revenueData['daily'] ?? []),
|
||||
const SizedBox(height: 32),
|
||||
_buildSectionTitle('نمو المستخدمين (آخر 30 يوم)'),
|
||||
_buildGrowthChart(ctrl.growthData),
|
||||
const SizedBox(height: 32),
|
||||
_buildSectionTitle('أفضل 10 سائقين (حسب الرحلات)'),
|
||||
_buildTopDriversList(ctrl.topDrivers),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
color: AppColor.textPrimary,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSummarySection(Map<String, dynamic>? summary) {
|
||||
if (summary == null) return const SizedBox();
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
_buildSummaryCard('إجمالي الإيرادات',
|
||||
'${summary['total_revenue_all'] ?? 0}', AppColor.info),
|
||||
const SizedBox(width: 12),
|
||||
_buildSummaryCard('صافي الربح', '${summary['total_profit_all'] ?? 0}',
|
||||
AppColor.success),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSummaryCard(String title, String value, Color color) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: color.withOpacity(0.3)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title,
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 12)),
|
||||
const SizedBox(height: 8),
|
||||
Text(value,
|
||||
style: TextStyle(
|
||||
color: color, fontSize: 22, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRevenueChart(List<dynamic> daily) {
|
||||
if (daily.isEmpty) return const Center(child: Text('لا توجد بيانات'));
|
||||
|
||||
List<FlSpot> revenueSpots = [];
|
||||
List<FlSpot> profitSpots = [];
|
||||
|
||||
for (int i = 0; i < daily.length; i++) {
|
||||
revenueSpots.add(FlSpot(i.toDouble(),
|
||||
double.tryParse(daily[i]['total_revenue'].toString()) ?? 0));
|
||||
profitSpots.add(FlSpot(i.toDouble(),
|
||||
double.tryParse(daily[i]['company_profit'].toString()) ?? 0));
|
||||
}
|
||||
|
||||
return Container(
|
||||
height: 300,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
child: LineChart(
|
||||
LineChartData(
|
||||
gridData: FlGridData(
|
||||
show: true,
|
||||
drawVerticalLine: false,
|
||||
getDrawingHorizontalLine: (v) =>
|
||||
FlLine(color: AppColor.divider, strokeWidth: 1)),
|
||||
titlesData: FlTitlesData(
|
||||
show: true,
|
||||
rightTitles:
|
||||
const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
topTitles:
|
||||
const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
bottomTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
getTitlesWidget: (val, meta) {
|
||||
if (val.toInt() % 7 == 0 && val.toInt() < daily.length) {
|
||||
return Text(
|
||||
daily[val.toInt()]['date'].toString().substring(8),
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 10));
|
||||
}
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
borderData: FlBorderData(show: false),
|
||||
lineBarsData: [
|
||||
LineChartBarData(
|
||||
spots: revenueSpots,
|
||||
isCurved: true,
|
||||
color: AppColor.info,
|
||||
barWidth: 3,
|
||||
isStrokeCapRound: true,
|
||||
dotData: const FlDotData(show: false),
|
||||
belowBarData: BarAreaData(
|
||||
show: true, color: AppColor.info.withOpacity(0.1)),
|
||||
),
|
||||
LineChartBarData(
|
||||
spots: profitSpots,
|
||||
isCurved: true,
|
||||
color: AppColor.success,
|
||||
barWidth: 3,
|
||||
isStrokeCapRound: true,
|
||||
dotData: const FlDotData(show: false),
|
||||
belowBarData: BarAreaData(
|
||||
show: true, color: AppColor.success.withOpacity(0.1)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGrowthChart(Map<String, dynamic> data) {
|
||||
final passengers = data['passenger_daily'] as List<dynamic>? ?? [];
|
||||
final drivers = data['driver_daily'] as List<dynamic>? ?? [];
|
||||
|
||||
if (passengers.isEmpty && drivers.isEmpty)
|
||||
return const Center(child: Text('لا توجد بيانات'));
|
||||
|
||||
List<BarChartGroupData> barGroups = [];
|
||||
int maxLength =
|
||||
passengers.length > drivers.length ? passengers.length : drivers.length;
|
||||
|
||||
for (int i = 0; i < maxLength; i++) {
|
||||
double pCount = i < passengers.length
|
||||
? double.tryParse(passengers[i]['new_passengers'].toString()) ?? 0
|
||||
: 0;
|
||||
double dCount = i < drivers.length
|
||||
? double.tryParse(drivers[i]['new_drivers'].toString()) ?? 0
|
||||
: 0;
|
||||
|
||||
barGroups.add(
|
||||
BarChartGroupData(
|
||||
x: i,
|
||||
barRods: [
|
||||
BarChartRodData(
|
||||
toY: pCount,
|
||||
color: AppColor.info,
|
||||
width: 8,
|
||||
borderRadius: BorderRadius.circular(4)),
|
||||
BarChartRodData(
|
||||
toY: dCount,
|
||||
color: AppColor.warning,
|
||||
width: 8,
|
||||
borderRadius: BorderRadius.circular(4)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
height: 250,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
child: BarChart(
|
||||
BarChartData(
|
||||
barGroups: barGroups,
|
||||
borderData: FlBorderData(show: false),
|
||||
titlesData: FlTitlesData(
|
||||
show: true,
|
||||
rightTitles:
|
||||
const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
topTitles:
|
||||
const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
bottomTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
getTitlesWidget: (val, meta) {
|
||||
if (val.toInt() % 7 == 0 && val.toInt() < passengers.length) {
|
||||
return Text(
|
||||
passengers[val.toInt()]['date'].toString().substring(8),
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 10));
|
||||
}
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTopDriversList(List<dynamic> drivers) {
|
||||
if (drivers.isEmpty) return const Center(child: Text('لا توجد بيانات'));
|
||||
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: drivers.length,
|
||||
itemBuilder: (ctx, i) {
|
||||
final d = drivers[i];
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
backgroundColor: AppColor.accent.withOpacity(0.1),
|
||||
child: Text('${i + 1}',
|
||||
style: const TextStyle(
|
||||
color: AppColor.accent, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('${d['first_name']} ${d['last_name']}',
|
||||
style: const TextStyle(
|
||||
color: AppColor.textPrimary,
|
||||
fontWeight: FontWeight.bold)),
|
||||
Text(d['phone'] ?? '',
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text('${d['completed_rides']} رحلة',
|
||||
style: const TextStyle(
|
||||
color: AppColor.info, fontWeight: FontWeight.bold)),
|
||||
Text('${d['total_revenue']} ج.م',
|
||||
style: const TextStyle(
|
||||
color: AppColor.success,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user