303 lines
11 KiB
Dart
303 lines
11 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
// تأكد من استيراد مكتبة الاتصال إذا أردت تفعيل زر الاتصال فعلياً
|
|
// import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import '../../../constant/box_name.dart';
|
|
import '../../../controller/functions/launch.dart';
|
|
import '../../../main.dart';
|
|
import '../../widgets/my_scafold.dart';
|
|
import '../../widgets/my_textField.dart';
|
|
import '../../widgets/mycircular.dart';
|
|
import '../../../constant/style.dart';
|
|
import '../../../controller/admin/captain_admin_controller.dart';
|
|
import 'captain_details.dart';
|
|
|
|
class CaptainsPage extends StatelessWidget {
|
|
CaptainsPage({super.key});
|
|
|
|
final CaptainAdminController captainController =
|
|
Get.put(CaptainAdminController());
|
|
final TextEditingController searchController = TextEditingController();
|
|
|
|
// 🔴 هام جداً: قم بتغيير هذا المتغير بناءً على حالة تسجيل الدخول الحقيقية في تطبيقك
|
|
// مثال: bool isAdmin = Get.find<AuthController>().isAdmin;
|
|
// final bool isAdmin = true; // اجعلها false لتجربة وضع المستخدم العادي
|
|
String myPhone = box.read(BoxName.adminPhone).toString();
|
|
|
|
// 2. تحديد من هو "السوبر أدمن" الذي يرى كل شيء
|
|
// يمكنك إضافة المزيد من الأرقام هنا باستخدام || أو قائمة
|
|
bool isSuperAdmin = false;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
isSuperAdmin = myPhone == '963942542053' || myPhone == '963992952235';
|
|
|
|
return MyScafolld(
|
|
title: 'Search for Captain'.tr,
|
|
isleading: true,
|
|
body: [
|
|
Container(
|
|
height: MediaQuery.of(context).size.height, // لضمان أخذ المساحة
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
children: [
|
|
// --- شريط البحث المحسن ---
|
|
_buildSearchSection(context),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
// --- قائمة النتائج ---
|
|
Expanded(
|
|
child: GetBuilder<CaptainAdminController>(
|
|
builder: (controller) {
|
|
if (controller.isLoading) {
|
|
return const Center(child: MyCircularProgressIndicator());
|
|
}
|
|
|
|
if (controller.captainData['message'] == null ||
|
|
controller.captainData['message'].isEmpty) {
|
|
return _buildEmptyState();
|
|
}
|
|
|
|
return ListView.separated(
|
|
physics: const BouncingScrollPhysics(),
|
|
itemCount: controller.captainData['message'].length,
|
|
separatorBuilder: (context, index) =>
|
|
const SizedBox(height: 12),
|
|
itemBuilder: (context, index) {
|
|
final captain =
|
|
controller.captainData['message'][index];
|
|
return _buildCaptainCard(context, captain);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
// مساحة إضافية في الأسفل لتجنب تداخل المحتوى مع الحواف
|
|
const SizedBox(height: 80),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// --- ودجت البحث ---
|
|
Widget _buildSearchSection(BuildContext context) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(15),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.1),
|
|
spreadRadius: 2,
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: MyTextForm(
|
|
controller: searchController,
|
|
label: 'Captain Phone Number'.tr,
|
|
hint: 'Enter phone number...'.tr,
|
|
type: TextInputType.phone,
|
|
// يمكنك إزالة الحواف من الـ TextField الأصلي إذا أردت ليتناسب مع الكونتينر
|
|
),
|
|
),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).primaryColor,
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: IconButton(
|
|
icon: const Icon(Icons.search, size: 28, color: Colors.white),
|
|
onPressed: () {
|
|
final phone = searchController.text;
|
|
if (phone.isNotEmpty) {
|
|
captainController.find_driver_by_phone(phone);
|
|
} else {
|
|
Get.snackbar(
|
|
'Error'.tr,
|
|
'Please enter a phone number to search.'.tr,
|
|
backgroundColor: Colors.red.withOpacity(0.8),
|
|
colorText: Colors.white,
|
|
);
|
|
}
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// --- بطاقة الكابتن المحسنة ---
|
|
Widget _buildCaptainCard(BuildContext context, dynamic captain) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.08),
|
|
spreadRadius: 1,
|
|
blurRadius: 8,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
border: Border.all(color: Colors.grey.withOpacity(0.1)),
|
|
),
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
borderRadius: BorderRadius.circular(16),
|
|
onTap: () {
|
|
Get.to(() => const CaptainDetailsPage(),
|
|
arguments: {'data': captain});
|
|
},
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: Row(
|
|
children: [
|
|
// صورة الكابتن أو أيقونة
|
|
CircleAvatar(
|
|
radius: 28,
|
|
backgroundColor:
|
|
Theme.of(context).primaryColor.withOpacity(0.1),
|
|
child: Icon(
|
|
Icons.person,
|
|
color: Theme.of(context).primaryColor,
|
|
size: 30,
|
|
),
|
|
),
|
|
const SizedBox(width: 15),
|
|
|
|
// المعلومات النصية
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// الاسم
|
|
Text(
|
|
'${captain['first_name']} ${captain['last_name']}',
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.black87,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
|
|
// رقم الهاتف (مع المنطق)
|
|
Row(
|
|
children: [
|
|
Icon(Icons.phone_iphone,
|
|
size: 14, color: Colors.grey[600]),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
_formatPhoneNumber(captain['phone'].toString()),
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.grey[700],
|
|
fontFamily:
|
|
'monospace', // لجعل الأرقام والنجوم متناسقة
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
// الإيميل (يظهر فقط للأدمن)
|
|
if (isSuperAdmin && captain['email'] != null) ...[
|
|
const SizedBox(height: 4),
|
|
Row(
|
|
children: [
|
|
Icon(Icons.email_outlined,
|
|
size: 14, color: Colors.grey[600]),
|
|
const SizedBox(width: 4),
|
|
Expanded(
|
|
child: Text(
|
|
captain['email'],
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: Colors.grey[600],
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
|
|
// أزرار الإجراءات
|
|
Column(
|
|
children: [
|
|
// زر الاتصال (فقط للأدمن)
|
|
if (isSuperAdmin)
|
|
IconButton(
|
|
onPressed: () {
|
|
// منطق الاتصال
|
|
makePhoneCall('+' + captain['phone']);
|
|
// Get.snackbar(
|
|
// 'Call', 'Calling ${captain['phone']}...');
|
|
},
|
|
icon: const Icon(Icons.call, color: Colors.green),
|
|
tooltip: 'Call Captain',
|
|
),
|
|
|
|
if (!isSuperAdmin)
|
|
const Icon(Icons.arrow_forward_ios,
|
|
size: 16, color: Colors.grey),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// --- دالة تنسيق الرقم (المنطق المطلوب) ---
|
|
String _formatPhoneNumber(String phone) {
|
|
if (isSuperAdmin) {
|
|
return phone; // للأدمن: إظهار الرقم كاملاً
|
|
} else {
|
|
// للمستخدم العادي: إظهار آخر 4 أرقام فقط
|
|
if (phone.length <= 4) return phone;
|
|
String lastFour = phone.substring(phone.length - 4);
|
|
String maskedPart = '*' * (phone.length - 4);
|
|
return '$maskedPart$lastFour'; // النتيجة: *******1234
|
|
}
|
|
}
|
|
|
|
// --- تصميم الحالة الفارغة ---
|
|
Widget _buildEmptyState() {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.search_off_rounded, size: 80, color: Colors.grey[300]),
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
'No captains found.'.tr,
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.w600,
|
|
color: Colors.grey[500],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|