إصلاح توافق فلاتر مع Theme الجديد

This commit is contained in:
Hamza-Ayed
2026-07-26 11:33:20 +03:00
parent 7830efead7
commit 3af99cc18a
31 changed files with 4256 additions and 2833 deletions
@@ -2,14 +2,8 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../constant/box_name.dart';
import '../../../constant/colors.dart';
import '../../../constant/style.dart';
import '../../../controller/admin/passenger_admin_controller.dart';
import '../../../main.dart'; // للوصول إلى box
import '../../widgets/elevated_btn.dart';
import '../../widgets/my_scafold.dart';
import '../../widgets/my_textField.dart';
import '../../widgets/mycircular.dart';
import '../../../main.dart';
import '../../widgets/snackbar.dart';
import 'passenger_details_page.dart';
@@ -21,141 +15,36 @@ class Passengrs extends StatelessWidget {
@override
Widget build(BuildContext context) {
// 1. منطق السوبر أدمن
final cs = Theme.of(context).colorScheme;
final isDark = Theme.of(context).brightness == Brightness.dark;
String myPhone = box.read(BoxName.adminPhone).toString();
bool isSuperAdmin = myPhone == '963942542053' || myPhone == '963992952235';
bool isSuperAdmin =
myPhone == '963942542053' || myPhone == '963992952235';
return MyScafolld(
title: 'Passengers Management'.tr,
isleading: true,
body: [
// استخدام Expanded أو Container بطول الشاشة لتجنب المشاكل
SizedBox(
height: Get.height, // تأمين مساحة العمل
child: GetBuilder<PassengerAdminController>(
builder: (controller) {
if (controller.isLoading) {
return const Center(child: MyCircularProgressIndicator());
}
return Column(
children: [
// --- قسم الإحصائيات والجوائز (Dashboard) ---
Padding(
padding: const EdgeInsets.all(16.0),
child: _buildDashboardCard(context, controller),
),
// --- عنوان القائمة ---
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"All Passengers".tr,
style: AppStyle.title.copyWith(
fontSize: 18, fontWeight: FontWeight.bold),
),
Text(
"${controller.passengersData['message']?.length ?? 0} Users",
style:
TextStyle(color: Colors.grey[600], fontSize: 12),
),
],
),
),
const SizedBox(height: 10),
// --- قائمة الركاب ---
// استخدام Expanded هنا هو الحل الجذري لمكلة Overflow
Expanded(
child: _buildPassengersList(controller, isSuperAdmin),
),
// مساحة سفلية صغيرة لضمان عدم التصاق القائمة بالحافة
const SizedBox(height: 20),
],
);
},
),
),
],
);
}
// --- تصميم بطاقة الإحصائيات (Dashboard) ---
Widget _buildDashboardCard(
BuildContext context, PassengerAdminController controller) {
// جلب العدد بأمان
final String countValue = (controller.passengersData['message'] != null &&
controller.passengersData['message'].isNotEmpty)
? controller.passengersData['message'][0]['countPassenger']
?.toString() ??
'0'
: '0';
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
blurRadius: 15,
offset: const Offset(0, 5),
),
],
),
child: Column(
return Scaffold(
backgroundColor: cs.surface,
body: Column(
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: AppColor.primaryColor.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(Icons.groups_rounded,
color: AppColor.primaryColor, size: 30),
),
const SizedBox(width: 15),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Total Passengers'.tr,
style: const TextStyle(fontSize: 14, color: Colors.grey),
),
Text(
countValue,
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
],
),
],
),
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
height: 45,
child: ElevatedButton.icon(
icon: const Icon(Icons.card_giftcard,
color: Colors.white, size: 20),
label: Text('Add Prize to Gold Passengers'.tr,
style: const TextStyle(
color: Colors.white, fontWeight: FontWeight.bold)),
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.yellowColor, // لون ذهبي
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
elevation: 0,
),
onPressed: () {
_showAddPrizeDialog(controller);
_buildAppBar(context, cs),
Expanded(
child: GetBuilder<PassengerAdminController>(
builder: (controller) {
if (controller.isLoading) {
return _buildLoadingState(cs);
}
return Column(
children: [
_buildDashboardCard(context, controller, cs),
_buildListHeader(context, controller, cs),
Expanded(
child: _buildPassengersList(
controller, isSuperAdmin, cs),
),
const SizedBox(height: 20),
],
);
},
),
),
@@ -164,20 +53,252 @@ class Passengrs extends StatelessWidget {
);
}
// --- بناء قائمة الركاب ---
Widget _buildAppBar(BuildContext context, ColorScheme cs) {
return Container(
padding: const EdgeInsets.fromLTRB(16, 50, 16, 16),
decoration: BoxDecoration(
color: cs.surface,
border: Border(bottom: BorderSide(color: cs.outline)),
),
child: Row(
children: [
GestureDetector(
onTap: () => Get.back(),
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: cs.surfaceContainerHighest,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: cs.outline),
),
child: Icon(Icons.arrow_back_ios_new_rounded,
color: cs.onSurfaceVariant, size: 16),
),
),
const SizedBox(width: 12),
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: cs.primary.withValues(alpha: 0.12),
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: cs.primary.withValues(alpha: 0.25)),
),
child: Icon(Icons.groups_rounded, color: cs.primary, size: 18),
),
const SizedBox(width: 10),
Text(
'إدارة الركاب',
style: TextStyle(
color: cs.onSurface,
fontSize: 18,
fontWeight: FontWeight.w700,
),
),
],
),
);
}
Widget _buildLoadingState(ColorScheme cs) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
width: 40,
height: 40,
child: CircularProgressIndicator(
color: cs.primary,
strokeWidth: 2,
backgroundColor: cs.primary.withValues(alpha: 0.1),
),
),
const SizedBox(height: 16),
Text('جاري تحميل الركاب...',
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 13)),
],
),
);
}
Widget _buildDashboardCard(
BuildContext context,
PassengerAdminController controller,
ColorScheme cs) {
final String countValue =
(controller.passengersData['message'] != null &&
controller.passengersData['message'].isNotEmpty)
? controller.passengersData['message'][0]['countPassenger']
?.toString() ??
'0'
: '0';
return Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: cs.surfaceContainerHighest,
borderRadius: BorderRadius.circular(20),
border: Border.all(color: cs.primary.withValues(alpha: 0.15)),
boxShadow: [
BoxShadow(
color: cs.primary.withValues(alpha: 0.06),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: Column(
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
cs.primary.withValues(alpha: 0.20),
cs.primary.withValues(alpha: 0.08),
],
),
borderRadius: BorderRadius.circular(14),
border: Border.all(
color: cs.primary.withValues(alpha: 0.25)),
),
child: Icon(Icons.groups_rounded,
color: cs.primary, size: 28),
),
const SizedBox(width: 16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'إجمالي الركاب',
style: TextStyle(
color: cs.onSurfaceVariant, fontSize: 12),
),
const SizedBox(height: 4),
Text(
countValue,
style: TextStyle(
color: cs.onSurface,
fontSize: 26,
fontWeight: FontWeight.w800,
height: 1,
),
),
],
),
],
),
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
height: 48,
child: ElevatedButton.icon(
icon: const Icon(Icons.card_giftcard,
color: Colors.white, size: 18),
label: Text('إضافة جائزة لركاب الذهب',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 13)),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFF59E0B),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14)),
elevation: 0,
),
onPressed: () {
_showAddPrizeDialog(controller, cs);
},
),
),
],
),
),
);
}
Widget _buildListHeader(
BuildContext context,
PassengerAdminController controller,
ColorScheme cs) {
return Padding(
padding: const EdgeInsets.fromLTRB(20, 16, 20, 8),
child: Row(
children: [
Container(
width: 3,
height: 14,
decoration: BoxDecoration(
color: cs.primary,
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 8),
Text(
'جميع الركاب',
style: TextStyle(
color: cs.onSurface,
fontSize: 15,
fontWeight: FontWeight.w600,
),
),
const SizedBox(width: 10),
Expanded(
child: Container(height: 1, color: cs.outline),
),
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: cs.primary.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: cs.primary.withValues(alpha: 0.2)),
),
child: Text(
'${controller.passengersData['message']?.length ?? 0}',
style: TextStyle(
color: cs.primary,
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
),
],
),
);
}
Widget _buildPassengersList(
PassengerAdminController controller, bool isSuperAdmin) {
final List<dynamic> passengers = controller.passengersData['message'] ?? [];
PassengerAdminController controller,
bool isSuperAdmin,
ColorScheme cs) {
final List<dynamic> passengers =
controller.passengersData['message'] ?? [];
if (passengers.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.person_off_outlined, size: 60, color: Colors.grey[300]),
const SizedBox(height: 10),
Text("No passengers found".tr,
style: TextStyle(color: Colors.grey[400])),
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: cs.surfaceContainerHighest,
shape: BoxShape.circle,
),
child: Icon(Icons.person_off_outlined,
size: 48, color: cs.onSurfaceVariant),
),
const SizedBox(height: 16),
Text('لا يوجد ركاب',
style: TextStyle(
color: cs.onSurfaceVariant, fontSize: 14)),
],
),
);
@@ -187,132 +308,171 @@ class Passengrs extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 16),
physics: const BouncingScrollPhysics(),
itemCount: passengers.length,
separatorBuilder: (context, index) => const SizedBox(height: 12),
separatorBuilder: (context, index) => const SizedBox(height: 10),
itemBuilder: (context, index) {
final user = passengers[index];
return _buildPassengerItem(user, isSuperAdmin);
return _buildPassengerItem(user, isSuperAdmin, cs);
},
);
}
// --- عنصر الراكب الواحد (Card) ---
Widget _buildPassengerItem(dynamic user, bool isSuperAdmin) {
Widget _buildPassengerItem(
dynamic user, bool isSuperAdmin, ColorScheme cs) {
String firstName = user['first_name'] ?? '';
String lastName = user['last_name'] ?? '';
String fullName = '$firstName $lastName'.trim();
if (fullName.isEmpty) fullName = 'Unknown User';
if (fullName.isEmpty) fullName = 'مستخدم';
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
border: Border.all(color: Colors.grey.withOpacity(0.1)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.05),
blurRadius: 5,
offset: const Offset(0, 2),
),
],
color: cs.surfaceContainerHighest,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: cs.outline),
),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.circular(15),
borderRadius: BorderRadius.circular(16),
onTap: () {
// الانتقال للتفاصيل مع تمرير صلاحية الأدمن
Get.to(
() => const PassengerDetailsPage(),
arguments: {'data': user, 'isSuperAdmin': isSuperAdmin},
);
},
child: Padding(
padding: const EdgeInsets.all(12.0),
padding: const EdgeInsets.all(14),
child: Row(
children: [
// Avatar
CircleAvatar(
radius: 25,
backgroundColor: AppColor.primaryColor.withOpacity(0.1),
child: Text(
fullName.isNotEmpty ? fullName[0].toUpperCase() : 'U',
style: TextStyle(
color: AppColor.primaryColor,
fontWeight: FontWeight.bold,
fontSize: 18),
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
cs.primary.withValues(alpha: 0.20),
cs.primary.withValues(alpha: 0.08),
],
),
borderRadius: BorderRadius.circular(14),
border: Border.all(
color: cs.primary.withValues(alpha: 0.2)),
),
child: Center(
child: Text(
fullName.isNotEmpty
? fullName[0].toUpperCase()
: 'U',
style: TextStyle(
color: cs.primary,
fontWeight: FontWeight.w800,
fontSize: 18,
),
),
),
),
const SizedBox(width: 15),
// Info
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
fullName,
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 16),
style: TextStyle(
color: cs.onSurface,
fontWeight: FontWeight.w600,
fontSize: 15,
),
),
const SizedBox(height: 4),
// Stats Row
const SizedBox(height: 6),
Row(
children: [
Icon(Icons.star_rounded,
size: 16, color: Colors.amber[700]),
Text(
" ${user['ratingPassenger'] ?? '0.0'} ",
style: const TextStyle(
fontSize: 12, fontWeight: FontWeight.bold),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: const Color(0xFFF59E0B)
.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(6),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.star_rounded,
size: 12, color: Color(0xFFF59E0B)),
const SizedBox(width: 3),
Text(
user['ratingPassenger']?.toString() ??
'0.0',
style: const TextStyle(
fontSize: 11,
fontWeight: FontWeight.w700,
color: Color(0xFFF59E0B),
),
),
],
),
),
const SizedBox(width: 8),
Icon(Icons.directions_car,
size: 14, color: Colors.grey[400]),
Text(
" ${user['countPassengerRide'] ?? '0'} Trips",
style: TextStyle(
fontSize: 12, color: Colors.grey[600]),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: cs.primary.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(6),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.directions_car_rounded,
size: 12, color: cs.primary),
const SizedBox(width: 3),
Text(
'${user['countPassengerRide'] ?? '0'} رحلة',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: cs.primary,
),
),
],
),
),
],
),
const SizedBox(height: 4),
// Phone Number (Masked logic)
const SizedBox(height: 6),
Row(
children: [
Icon(Icons.phone_iphone,
size: 12, color: Colors.grey[400]),
Icon(Icons.phone_iphone_rounded,
size: 12, color: cs.onSurfaceVariant),
const SizedBox(width: 4),
Text(
_formatPhoneNumber(
user['phone'].toString(), isSuperAdmin),
style: TextStyle(
fontSize: 12,
color: Colors.grey[500],
fontFamily: 'monospace'),
fontSize: 11,
color: cs.onSurfaceVariant,
fontFamily: 'monospace',
),
),
],
),
// Email (Show only if Super Admin)
if (isSuperAdmin && user['email'] != null) ...[
const SizedBox(height: 2),
const SizedBox(height: 3),
Text(
user['email'],
style:
TextStyle(fontSize: 10, color: Colors.grey[400]),
style: TextStyle(
fontSize: 10, color: cs.onSurfaceVariant),
maxLines: 1,
overflow: TextOverflow.ellipsis,
)
]
),
],
],
),
),
// Arrow
Icon(Icons.arrow_forward_ios_rounded,
size: 16, color: Colors.grey[300]),
size: 14, color: cs.onSurfaceVariant),
],
),
),
@@ -321,63 +481,89 @@ class Passengrs extends StatelessWidget {
);
}
// --- دالة تنسيق الرقم (إظهار آخر 4 أرقام لغير الأدمن) ---
String _formatPhoneNumber(String phone, bool isSuperAdmin) {
if (isSuperAdmin) return phone; // إظهار الرقم كاملاً للسوبر أدمن
// لغير الأدمن
if (isSuperAdmin) return phone;
if (phone.length <= 4) return phone;
String lastFour = phone.substring(phone.length - 4);
String masked = '*' * (phone.length - 4);
return '$masked$lastFour'; // النتيجة: *******5678
return '$masked$lastFour';
}
// --- دالة إضافة الجوائز ---
void _showAddPrizeDialog(PassengerAdminController controller) {
// التحقق من يوم السبت
void _showAddPrizeDialog(
PassengerAdminController controller, ColorScheme cs) {
if (DateTime.now().weekday == DateTime.saturday) {
Get.defaultDialog(
title: 'Add Prize'.tr,
titleStyle: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
title: 'إضافة جائزة',
titleStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
color: cs.onSurface),
backgroundColor: cs.surface,
contentPadding: const EdgeInsets.all(20),
content: Form(
key: controller.formPrizeKey,
child: Column(
children: [
Text(
'Add Points to Gold Passengers wallet'.tr,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
content: Column(
children: [
Text(
'إضافة نقاط لمحفظة ركاب الذهب',
textAlign: TextAlign.center,
style:
TextStyle(color: cs.onSurfaceVariant, fontSize: 13),
),
const SizedBox(height: 20),
TextFormField(
controller: controller.passengerPrizeController,
keyboardType: TextInputType.number,
style: TextStyle(color: cs.onSurface),
cursorColor: cs.primary,
decoration: InputDecoration(
labelText: 'مبلغ الجائزة',
hintText: '1000...',
filled: true,
fillColor: cs.surfaceContainerHighest,
labelStyle: TextStyle(color: cs.onSurfaceVariant),
hintStyle: TextStyle(color: cs.onSurfaceVariant),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: cs.outline),
borderRadius: BorderRadius.circular(14),
),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: cs.primary, width: 1.5),
borderRadius: BorderRadius.circular(14),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 14),
),
const SizedBox(height: 20),
MyTextForm(
controller: controller.passengerPrizeController,
label: 'Prize Amount'.tr,
hint: '1000...',
type: TextInputType.number,
),
],
),
),
],
),
confirm: SizedBox(
width: 120,
child: MyElevatedButton(
title: 'Add',
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: cs.primary,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
elevation: 0,
),
onPressed: () async {
if (controller.formPrizeKey.currentState!.validate()) {
controller.addPassengerPrizeToWalletSecure();
Get.back();
}
},
child: const Text('إضافة',
style: TextStyle(fontWeight: FontWeight.bold)),
),
),
cancel: TextButton(
onPressed: () => Get.back(),
child:
Text('Cancel'.tr, style: const TextStyle(color: Colors.grey))),
onPressed: () => Get.back(),
child: Text('إلغاء',
style: TextStyle(color: cs.onSurfaceVariant)),
),
);
} else {
mySnackbarWarning('Prizes can only be added on Saturdays.'.tr);
mySnackbarWarning('يمكن إضافة الجوائز يوم السبت فقط');
}
}
}